public void Train(World world) { int limit = 0; int noChangeScore = int.MinValue + 1000; int noChangeCounter = 0; while (world.Snake.Alive && world.Score > -1000 && limit < 10000) //Limit runtime { if (world.Score == noChangeScore) { noChangeCounter++; } else { noChangeScore = world.Score; noChangeCounter = 0; } if (noChangeCounter > 300) //No food picked in 300 cycles? Running in cycles..:( { world.Score = int.MinValue + 1000; } SnakeNeuralAI.MakeDecision(world); limit++; } this.Score = world.Score; // (this.Score + world.Score + Math.Max(this.Score, world.Score) * 10) / 12; }
public static SnakeNeuralAI Clone(NeuralNetwork network, bool learn) { SnakeNeuralAI clone = new SnakeNeuralAI(learn, new NeuralNetwork(network)); if (learn) { clone.Network.Mutate(); } return(clone); }
public SnakeNeuralAiTrainer(SnakeNeuralAI snakeNeuralAI) { this.SnakeNeuralAI = snakeNeuralAI; this.Score = 0; }