Exemple #1
0
        public FitnessInfo Evaluate(IBlackBox box)
        {
            double fitness = 0;

            //generate the brain with the algorithm
            IPlayer p1 = new NeatBrain(box);
            IPlayer p2 = new RandomBrain();

            //Play 100 games
            for (int i = 0; i < 100; i++)
            {
                Game Game = new Game(p1, p2);
                try
                {
                    Game.PlayUntilFinished();
                    //score
                    fitness += GetScore(Game.GetGameState());
                }
                catch
                {
                    fitness += Game.NumberOfMoves;
                }
            }

            return(new FitnessInfo(fitness, fitness));
        }
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            if (_match != null)
            {
                _match.Moved -= match_Moved;
                _match.Player1.Detach(this);
                _match.Player2.Detach(this);
            }
            Brain <CthelloMove> player1, player2;

            switch (cmbPlayer1.SelectedIndex)
            {
            case 0:
                player1 = new InteractiveBrain <CthelloMove>();
                break;

            case 1:
                player1 = new RandomBrain <CthelloMove>();
                break;

            case 2:
                player1 = new MinimaxBrain <CthelloMove>();
                (player1 as MinimaxBrain <CthelloMove>).Depth = cmbPlayer1Param.SelectedIndex;
                break;

            default:
                player1 = null;
                MessageBox.Show("Bitte wählen Sie einen gültigen Spieler aus.");
                break;
            }
            switch (cmbPlayer2.SelectedIndex)
            {
            case 0:
                player2 = new InteractiveBrain <CthelloMove>();
                break;

            case 1:
                player2 = new RandomBrain <CthelloMove>();
                break;

            case 2:
                player2 = new MinimaxBrain <CthelloMove>();
                (player2 as MinimaxBrain <CthelloMove>).Depth = cmbPlayer2Param.SelectedIndex;
                break;

            default:
                player2 = null;
                MessageBox.Show("Bitte wählen Sie einen gültigen Spieler aus.");
                break;
            }
            player1.Attach(this);
            player2.Attach(this);
            _match = new CthelloMatch(player1, player2);
            DisplayMatch(false);
            _match.Moved += match_Moved;
            UpdateStatus();
            _match.NextMove();
        }