|
@@ -39,7 +39,6 @@ import (
|
|
|
|
|
|
genetic "git.semlanik.org/semlanik/NeuralNetwork/genetic"
|
|
genetic "git.semlanik.org/semlanik/NeuralNetwork/genetic"
|
|
neuralnetwork "git.semlanik.org/semlanik/NeuralNetwork/neuralnetwork"
|
|
neuralnetwork "git.semlanik.org/semlanik/NeuralNetwork/neuralnetwork"
|
|
- remotecontrol "git.semlanik.org/semlanik/NeuralNetwork/remotecontrol"
|
|
|
|
grpc "google.golang.org/grpc"
|
|
grpc "google.golang.org/grpc"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -48,7 +47,6 @@ type SnakeSimulator struct {
|
|
snake *Snake
|
|
snake *Snake
|
|
maxVerificationSteps int
|
|
maxVerificationSteps int
|
|
stats *Stats
|
|
stats *Stats
|
|
- remoteControl *remotecontrol.RemoteControl
|
|
|
|
|
|
|
|
//GUI interface part
|
|
//GUI interface part
|
|
speed uint32
|
|
speed uint32
|
|
@@ -87,7 +85,6 @@ func NewSnakeSimulator(maxVerificationSteps int) (s *SnakeSimulator) {
|
|
isPlayingUpdateQueue: make(chan bool, 1),
|
|
isPlayingUpdateQueue: make(chan bool, 1),
|
|
speedQueue: make(chan uint32, 1),
|
|
speedQueue: make(chan uint32, 1),
|
|
speed: 10,
|
|
speed: 10,
|
|
- remoteControl: remotecontrol.NewRemoteControl(),
|
|
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
@@ -95,7 +92,6 @@ func NewSnakeSimulator(maxVerificationSteps int) (s *SnakeSimulator) {
|
|
// Population test method
|
|
// Population test method
|
|
// Verifies population and returns unsorted finteses for each individual
|
|
// Verifies population and returns unsorted finteses for each individual
|
|
func (s *SnakeSimulator) Verify(population *genetic.Population) (fitnesses []*genetic.IndividalFitness) {
|
|
func (s *SnakeSimulator) Verify(population *genetic.Population) (fitnesses []*genetic.IndividalFitness) {
|
|
- s.remoteControl.Init(population.Networks[0])
|
|
|
|
s.stats.Generation++
|
|
s.stats.Generation++
|
|
s.statsUpdateQueue <- true
|
|
s.statsUpdateQueue <- true
|
|
|
|
|
|
@@ -133,12 +129,10 @@ func (s *SnakeSimulator) Verify(population *genetic.Population) (fitnesses []*ge
|
|
// Play best of the best
|
|
// Play best of the best
|
|
s.isPlaying = false
|
|
s.isPlaying = false
|
|
s.isPlayingUpdateQueue <- s.isPlaying
|
|
s.isPlayingUpdateQueue <- s.isPlaying
|
|
- population.GetBestNetwork().SetStateWatcher(s.remoteControl)
|
|
|
|
s.runSnake(population.GetBestNetwork(), false)
|
|
s.runSnake(population.GetBestNetwork(), false)
|
|
population.GetBestNetwork().SetStateWatcher(nil)
|
|
population.GetBestNetwork().SetStateWatcher(nil)
|
|
} else {
|
|
} else {
|
|
- // Pley best from generation
|
|
|
|
- population.Networks[fitnesses[0].Index].SetStateWatcher(s.remoteControl)
|
|
|
|
|
|
+ // Play best from generation
|
|
s.runSnake(population.Networks[fitnesses[0].Index], false)
|
|
s.runSnake(population.Networks[fitnesses[0].Index], false)
|
|
population.Networks[fitnesses[0].Index].SetStateWatcher(nil)
|
|
population.Networks[fitnesses[0].Index].SetStateWatcher(nil)
|
|
}
|
|
}
|
|
@@ -149,7 +143,6 @@ func (s *SnakeSimulator) Verify(population *genetic.Population) (fitnesses []*ge
|
|
func (s *SnakeSimulator) PlayBestNetwork(network *neuralnetwork.NeuralNetwork) {
|
|
func (s *SnakeSimulator) PlayBestNetwork(network *neuralnetwork.NeuralNetwork) {
|
|
|
|
|
|
for s.repeatInLoop {
|
|
for s.repeatInLoop {
|
|
- s.remoteControl.Init(network)
|
|
|
|
s.stats.Generation++
|
|
s.stats.Generation++
|
|
s.statsUpdateQueue <- true
|
|
s.statsUpdateQueue <- true
|
|
|
|
|
|
@@ -167,7 +160,6 @@ func (s *SnakeSimulator) PlayBestNetwork(network *neuralnetwork.NeuralNetwork) {
|
|
s.isPlayingUpdateQueue <- s.isPlaying
|
|
s.isPlayingUpdateQueue <- s.isPlaying
|
|
prevSpeed := s.speed
|
|
prevSpeed := s.speed
|
|
s.speed = 5
|
|
s.speed = 5
|
|
- network.SetStateWatcher(s.remoteControl)
|
|
|
|
s.runSnake(network, false)
|
|
s.runSnake(network, false)
|
|
network.SetStateWatcher(nil)
|
|
network.SetStateWatcher(nil)
|
|
s.speed = prevSpeed
|
|
s.speed = prevSpeed
|
|
@@ -434,8 +426,6 @@ func (s *SnakeSimulator) StartServer() {
|
|
fmt.Printf("Failed to serve: %v\n", err)
|
|
fmt.Printf("Failed to serve: %v\n", err)
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
-
|
|
|
|
- go s.remoteControl.Run()
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// Steaming of Field updates
|
|
// Steaming of Field updates
|