コード例 #1
0
        public double Evaluate(IChromosome chromosome)
        {
            var m      = this.maze.Copy();
            var genes  = chromosome.GetGenes();
            var walker = new MazeWalker(m, genes);
            int repeatedSteps;
            int closest;
            var steps = walker.Walk(out repeatedSteps, out closest);

            if (steps < int.MaxValue)
            {
                steps = steps + repeatedSteps;
            }
            else
            {
                steps -= this.maze.Height * this.maze.Width * 50;                 // prevent overflow
                var open = 0;

                for (int x = 0; x < this.maze.Width; x++)
                {
                    for (int y = 0; y < this.maze.Height; y++)
                    {
                        if (m[x, y] == Maze.State.Open)
                        {
                            open++;
                        }
                    }
                }
                steps += (open * 50) + ((int)closest * 2);
            }

            return(-(steps));
        }
コード例 #2
0
        private static Maze FillMazeStepsWalked(Maze m, IChromosome chromosome)
        {
            var winnerSteps = m.Copy();
            var w           = new MazeWalker(winnerSteps, chromosome.GetGenes());
            int repeatedSteps;
            int closest;

            w.Walk(out repeatedSteps, out closest);
            return(winnerSteps);
        }