Example #1
0
 public Game(int width, int height, int snake_length)
 {
     this.snake_length = snake_length;
     snake_length_count = snake_length;
     this.width = width;
     this.height = height;
     board = new Entity[width, height];
     controller = new FFNN(40, 6, 3);
 }
Example #2
0
        public Game(int width, int height, int snake_length, int vision, bool smell)
        {
            if (vision < 1)
                throw new ArgumentOutOfRangeException("vision must be 1 or more");

            //snake properties
            this.vision = vision;
            this.smell = smell;
            this.snake_length = snake_length;
            snake_length_count = snake_length;
            controller = new FFNN(vision * 12 + (smell ? 4 : 0), 6, 3);

            //board properties
            this.width = width;
            this.height = height;
            board = new Entity[width, height];
        }
Example #3
0
 // ===========================================================================================
 //  CONSTRUCTOR
 /*
  * I used this link when I wrote the GA to remember the structure of the program:
  * http://cstheory.stackexchange.com/questions/14758/tournament-selection-in-genetic-algorithms
  * selection modifier could be % of pop chosen for tournament selection... depends on selection implementation
  */
 public GA( Game snake, int pop_size )
 {
     // DEFAULT PROPERTY VALUES
     ProbMutate = (float)0.05;
     StdDev = (float)0.50;
     SelectMod = (float)0.10;
     NumRuns = (int)30;
     // INITIALIZE VARIABLES
     SnakeGame = (Game)snake;
     NeuralNet = snake.GetNN();
     Genes = NeuralNet.NumWeights;
     PopSize = pop_size;
     Population = new double[PopSize][];
     for (int p = 0; p < pop_size; p++)
         Population[p] = new double[Genes];
     Fitnesses = new double[PopSize];
     // CREATE AN ARRAY FOR TOURNAMENT SELECTION
     shuffled = new int[pop_size];
     for (int x = 0; x < pop_size; x++) { shuffled[x] = x; }
     ShuffleArray(shuffled); // SHUFFLE IT ONCE BEFORE USE
 }