Ejemplo n.º 1
0
        private void SetupGame()
        {
            _myGame.ResetBoard();
            _myAgent     = GetAgent();
            _myPlayer    = PlayerSelectComboBox.SelectedItem.ToString() == BoardStates.white.ToString() ? BoardStates.black : BoardStates.white;
            _boardPanels = new PiecePanel[OthelloGame.BOARD_SIZE, OthelloGame.BOARD_SIZE];
            int tileSize = ((Size.Width > Size.Height) ? Size.Height - 45 : Size.Width - 45) / OthelloGame.BOARD_SIZE;

            for (int i = 0; i < OthelloGame.BOARD_SIZE; i++)
            {
                for (int j = 0; j < OthelloGame.BOARD_SIZE; j++)
                {
                    var newPanel = new PiecePanel(new int[] { i, j })
                    {
                        Size     = new Size(tileSize, tileSize),
                        Location = new Point(tileSize * i, tileSize * j)
                    };

                    newPanel.MouseClick += new MouseEventHandler(OthelloPeice_Click);
                    Controls.Add(newPanel);
                    _boardPanels[i, j] = newPanel;

                    Color panelcolor = Color.Red;
                    if (BoardColorDictionary.BoardStateColors.TryGetValue(_myGame.GetBoard()[i, j], out panelcolor))
                    {
                        _boardPanels[i, j].ReColor(panelcolor);
                    }
                }
            }
            if (_myGame.WhosTurn != _myPlayer)
            {
                _myGame.MakeMove(_myAgent.MakeMove(_myGame, ~_myPlayer));
            }
        }
Ejemplo n.º 2
0
        private void SetupBoard()
        {
            _myGame            = new OthelloGame();
            _myAgent           = new MinMaxAgent();
            _boardPanels       = new PiecePanel[OthelloGame.BOARD_SIZE, OthelloGame.BOARD_SIZE];
            _currentViewedMove = 0;
            int tileSize = ((Size.Width > Size.Height) ? Size.Height - 45 : Size.Width - 45) / OthelloGame.BOARD_SIZE;

            for (int i = 0; i < OthelloGame.BOARD_SIZE; i++)
            {
                for (int j = 0; j < OthelloGame.BOARD_SIZE; j++)
                {
                    var newPanel = new PiecePanel(new int[] { i, j })
                    {
                        Size     = new Size(tileSize, tileSize),
                        Location = new Point(tileSize * i, tileSize * j)
                    };

                    newPanel.MouseClick += new MouseEventHandler(OthelloPeice_Click);
                    Controls.Add(newPanel);
                    _boardPanels[i, j] = newPanel;

                    Color panelcolor = Color.Red;
                    if (BoardColorDictionary.BoardStateColors.TryGetValue(_myGame.GetBoard()[i, j], out panelcolor))
                    {
                        _boardPanels[i, j].ReColor(panelcolor);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void EducatedPlayButton_Click(object sender, EventArgs e)
        {
            EnableControlButtons(false);
            new Thread(() =>
            {
                int unused = 0;
                _myAgent   = new MinMaxAgent(new HeuristicAgent(), Convert.ToInt32(MoveDepth.Text));
                _myGame.MakeMove(_myGame.WhosTurn, _myAgent.MakeMove(_myGame, _myGame.WhosTurn));

                Invoke(new Action(() =>
                {
                    RefreshControls();
                    EnableControlButtons();
                }));
            }).Start();
        }
Ejemplo n.º 4
0
        public static FloatingPointChromosome EvolveGeneticAlgorithm(FloatingPointChromosome chromosome, IOthelloAgent agent, string chromosomeLabel = "")
        {
            IPopulation population = new TplPopulation(30, 60, chromosome);
            IFitness    fitness    = new EvaluationFitness(agent);
            ISelection  selection  = new RouletteWheelSelection(); //Guess
            ICrossover  crossover  = new UniformCrossover();       //Guess
            IMutation   mutation   = new UniformMutation();        //Guess


            ITermination stagnation = new FitnessStagnationTermination(500);
            ITermination threshold  = new FitnessThresholdTermination(.9);

            ITaskExecutor taskExecutor = new ParallelTaskExecutor()
            {
                MaxThreads = Environment.ProcessorCount,
                MinThreads = Environment.ProcessorCount / 2
            };


            GeneticAlgorithm algorithm = new GeneticAlgorithm(population, fitness, selection, crossover, mutation)
            {
                TaskExecutor        = new TplTaskExecutor(),
                MutationProbability = .2f
            };

            algorithm.TaskExecutor = taskExecutor;
            algorithm.Termination  = stagnation;

            algorithm.Start();

            SaveChromosome((FloatingPointChromosome)algorithm.BestChromosome, chromosomeLabel);

            Debug.WriteLine("finished Training, with {0} time spent on evolving", algorithm.TimeEvolving);
            Debug.WriteLine("fitness of this generation vs the last : {0}", algorithm.Fitness);

            return((FloatingPointChromosome)algorithm.BestChromosome);
        }
Ejemplo n.º 5
0
 public EvaluationFitness(IOthelloAgent agent, int testCount = 100) : base()
 {
     opposingAgent = agent;
     TEST_COUNT    = testCount;
 }