예제 #1
0
        public double EvaluateNetwork(INetwork network)
        {
            INetwork tempNet = null;

            NeatGenome.NeatGenome tempGenome = null;

            tempGenome = substrate.generateGenome(network);

            tempNet = tempGenome.Decode(null);
            SharpNeatExperiments.Pacman.MyForm1.neatGenome = tempGenome;
            SharpNeatExperiments.Pacman.MyForm1.network    = tempNet;

            double retries      = 5;
            double totalFitness = 0;

            for (int i = 0; i < retries; i++)
            {
                var pacman = new PacmanAINeural.NeuralPacmanSUPG();
                //pacman.SetBrain(network);
                pacman.SetBrain(tempNet, true, tempGenome, network, substrate.getSUPGMap());

                var simplePacmanController = new PacmanAINeural.SimplePacmanController();
                simplePacmanController.SetBrain(tempNet, true, tempGenome, network, substrate.getSUPGMap());

                Visualizer visualizer = null;
                SharpNeatExperiments.Pacman.SimplePacman simplePacman = null;
                Thread visualizerThread;

                visualizerThread = new System.Threading.Thread(delegate()
                {
                    bool fastNoDraw = false;
                    simplePacman    = new SharpNeatExperiments.Pacman.SimplePacman(simplePacmanController, fastNoDraw);
                    if (!fastNoDraw)
                    {
                        System.Windows.Forms.Application.Run(simplePacman);
                    }

                    //visualizer = new Visualizer(pacman);
                    //System.Windows.Forms.Application.Run(visualizer);
                });
                visualizerThread.Start();
                visualizerThread.Join();

                totalFitness += simplePacman.returnGameScore;// visualizer.returnGameState;
            }
            double avgFitness = totalFitness / retries;

            return(avgFitness);

            /*int time = visualizer.returnGameState;
             * return (double)time;//fitness;*/
        }
예제 #2
0
        public double[] EvaluateNetworkMultipleObjective(INetwork network)
        {
            INetwork tempNet = null;

            NeatGenome.NeatGenome tempGenome = null;

            tempGenome = substrate.generateGenome(network);

            tempNet = tempGenome.Decode(null);
            SharpNeatExperiments.Pacman.MyForm1.neatGenome = tempGenome;
            SharpNeatExperiments.Pacman.MyForm1.network    = tempNet;

            double retries        = 1;
            double totalFitness   = 0;
            double totalEatScore  = 0;
            double totalLifeScore = 0;

            for (int i = 0; i < retries; i++)
            {
                var pacman = new PacmanAINeural.NeuralPacmanSUPG();
                //pacman.SetBrain(network);
                pacman.SetBrain(tempNet, true, tempGenome, network, substrate.getSUPGMap());

                var simplePacmanController = new PacmanAINeural.SimplePacmanController();
                simplePacmanController.SetBrain(tempNet, true, tempGenome, network, substrate.getSUPGMap());

                Visualizer visualizer = null;
                SharpNeatExperiments.Pacman.SimplePacman simplePacman = null;
                Thread visualizerThread;

                visualizerThread = new System.Threading.Thread(delegate()
                {
                    simplePacman = new SharpNeatExperiments.Pacman.SimplePacman(simplePacmanController, false);
                    System.Windows.Forms.Application.Run(simplePacman);

                    //visualizer = new Visualizer(pacman);
                    //System.Windows.Forms.Application.Run(visualizer);
                });
                visualizerThread.Start();
                visualizerThread.Join();

                totalFitness   += simplePacman.returnGameScore;
                totalEatScore  += simplePacman.returnEatScore;
                totalLifeScore += simplePacman.returnLifeScore;
            }
            double avgFitness   = totalFitness / retries;
            double avgEatScore  = totalEatScore / retries;
            double avgLifeScore = totalLifeScore / retries;

            return(new double[] { avgFitness, avgEatScore, avgLifeScore });
        }
예제 #3
0
        public SimplePacman(PacmanAINeural.SimplePacmanController controller, bool fastNoDraw, Random rand = null)
        {
            InitializeComponent();
            KeyDown += new KeyEventHandler(keyDownHandler);
            KeyUp   += new KeyEventHandler(keyUpHandler);

            keys_down = new bool[1];
            key_props = new[] { Keys.Up, Keys.Down, Keys.Left, Keys.Right };

            width  = Picture.Width / zoom;
            height = Picture.Height / zoom;
            image  = new Bitmap(Picture.Width, Picture.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            g      = Graphics.FromImage(image);

            if (controller != null)
            {
                this.controller = controller;
            }
            else
            {
                this.controller = new PacmanAINeural.SimplePacmanController();
            }
            this.controller.gameState = this;

            enemies = new PacmanAINeural.SimplePacmanEnemyController[3];

            for (int i = 0; i < enemies.Length; i++)
            {
                enemies[i] = new PacmanAINeural.SimplePacmanEnemyController(this);
                enemies[i].reactionTime = (i * 15) + 10;
            }
            controller.pos = new Point(3 * width / 8, 3 * height / 8);
            enemies[0].pos = new Point(width / 8, height / 8);
            enemies[1].pos = new Point(6 * width / 8, height / 8);

            /*enemies[2].pos = new Point(  width / 8, 6*height / 8);
            *  enemies[3].pos = new Point(6*width / 8, 6*height / 8);*/

            //int myData = 0; // dummy data

            /*tickHandler = new TimerEventHandler(tick);
             * fastTimer = timeSetEvent(fastNoDraw ? 1 : 20, fastNoDraw? 1:20, tickHandler, ref myData, 1);*/

            Application.ApplicationExit += new EventHandler(closeHandler);

            if (rand == null)
            {
                Random = new Random();
            }
            else
            {
                Random = rand;
            }
            this.fastNoDraw = fastNoDraw;
            if (fastNoDraw)
            {
                loop();
            }
            else
            {
                loopWithWaiting();

                /*int myData = 0; // dummy data
                 * tickHandler = new TimerEventHandler(tick);
                 * fastTimer = timeSetEvent(fastNoDraw ? 1 : 20, fastNoDraw? 1:20, tickHandler, ref myData, 1);*/
            }
        }