コード例 #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 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      = 1;
            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 supgonlyController = new PacmanAINeural.SUPGONLYController();
                supgonlyController.SetBrain(tempNet, true, tempGenome, network, substrate.getSUPGMap());

                Thread visualizerThread;

                visualizerThread = new System.Threading.Thread(delegate()
                {
                    int tmpCounter = 0;
                    while (tmpCounter < 200)
                    {
                        //supgonlyController.dummyMasterFreqValue = (float)Math.Sin(tmpCounter*0.1f);
                        if (tmpCounter % 50 == 0)
                        {
                            supgonlyController.makeAChangeInMasterFreq();
                        }
                        if (tmpCounter == 80)
                        {
                            //supgonlyController.makeAChangeInMasterFreq();
                        }
                        supgonlyController.Think();

                        /*simplePacman = new SharpNeatExperiments.Pacman.SimplePacman(simplePacmanController);
                         * System.Windows.Forms.Application.Run(simplePacman);*/

                        //visualizer = new Visualizer(pacman);
                        //System.Windows.Forms.Application.Run(visualizer);
                        //Thread.Sleep(50);
                        tmpCounter++;
                    }
                });
                visualizerThread.Start();
                visualizerThread.Join();

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

            //Console.WriteLine("newEvaluation" + avgFitness);
            return(avgFitness);

            /*int time = visualizer.returnGameState;
             * return (double)time;//fitness;*/
        }