Alexey Edelev %!s(int64=5) %!d(string=hai) anos
pai
achega
b2e095a1c2

+ 3 - 2
neuralnetwork/snakesimulator/snakesimulator.go

@@ -72,7 +72,8 @@ func (s *SnakeSimulator) Verify(population *genetic.Population) (fitnesses []*ge
 
 		s.runSnake(inidividual, false)
 		fitnesses[index] = &genetic.IndividalFitness{
-			Fitness: float64(s.stats.Move),
+			// Fitness: float64(s.stats.Move), //Uncomment this to decrese food impact to individual selection
+			Fitness: float64(s.stats.Move) * float64(len(s.snake.Points)-2),
 			Index:   index,
 		}
 	}
@@ -84,7 +85,7 @@ func (s *SnakeSimulator) Verify(population *genetic.Population) (fitnesses []*ge
 
 	//Best snake showtime!
 	prevSpeed := s.speed
-	s.speed = 2
+	s.speed = 5
 	s.runSnake(population.Networks[fitnesses[0].Index], false)
 	s.speed = prevSpeed
 	return

+ 47 - 20
neuralnetwork/snakesimulator/snakesimulatorui/main.qml

@@ -33,11 +33,11 @@ ApplicationWindow {
     id: root
     visible: true
     property int tileSize: 20
-    width: field.width*tileSize
+    width: field.width*tileSize + sideBar.width
     height: field.height*tileSize
 
     Rectangle {
-        color: "#000000"
+        color: "#565656"
         anchors.fill: parent
     }
 
@@ -53,34 +53,61 @@ ApplicationWindow {
     }
 
     Rectangle {
-        color: "#eeffee"
+        color: "#99ee99"
         x: field.food.x*tileSize
         y: field.food.y*tileSize
         width: tileSize
         height: tileSize
     }
 
-    Column {
+    Rectangle {
+        id: sideBar
+        width: speedTextField.width + contentColumn.anchors.margins*2
+        color: "#000000"
         anchors {
             right: parent.right
             top: parent.top
-            margins: 10
-        }
-        Text {
-            color: "#ddffee"
-            text: "Generation: " + stats.generation
-        }
-        Text {
-            color: "#ddffee"
-            text: "Individual: " + stats.individual
-        }
-        Text {
-            color: "#ddffee"
-            text: "Move: " + stats.move
+            bottom: parent.bottom
         }
-        TextField {
-            onAccepted:  {
-                client.setSpeed(parseInt(text, 10))
+        Column {
+            id: contentColumn
+            anchors.fill: parent
+            anchors.margins: 10
+            spacing: 10
+            Text {
+                font.pointSize: 14
+                font.weight: Font.Bold
+                color: "#ffffff"
+                text: "Generation: " + stats.generation
+            }
+            Text {
+                font.pointSize: 14
+                font.weight: Font.Bold
+                color: "#ffffff"
+                text: "Individual: " + stats.individual
+            }
+            Text {
+                font.pointSize: 14
+                font.weight: Font.Bold
+                color: "#ffffff"
+                text: "Move: " + stats.move
+            }
+            Text {
+                font.pointSize: 14
+                font.weight: Font.Bold
+                color: "#ffffff"
+                text: "Speed: "
+            }
+            TextField {
+                id: speedTextField
+                font.pointSize: 14
+                validator: RegExpValidator {
+                    regExp: /1?[0-9]{1}/
+                }
+
+                onAccepted:  {
+                    client.setSpeed(parseInt(text, 10))
+                }
             }
         }
     }