Пример #1
0
        private void Click_Start(object sender, EventArgs e)
        {
            String box1    = (String)p1.SelectedItem;
            String box2    = (String)p2.SelectedItem;
            Player player1 = null;
            Player player2 = null;

            switch (box1)
            {
            case "Random Player":
                player1 = new RandomPlayer(1, true);
                break;

            case "Heuristic Player":
                player1 = new HeuristicAIPlayer(1, true);
                break;

            case "Min-Max Player":
                player1 = new MinMaxPlayer(1, true);
                break;

            case "Human Player":
                player1 = new HumanPlayer(1, true);
                break;
            }

            switch (box2)
            {
            case "Random Player":
                player2 = new RandomPlayer(2, false);
                break;

            case "Heuristic Player":
                player2 = new HeuristicAIPlayer(2, false);
                break;

            case "Min-Max Player":
                player2 = new MinMaxPlayer(2, false);
                break;

            case "Human Player":
                player2 = new HumanPlayer(2, false);
                break;
            }

            Clear();

            Task.Factory.StartNew(() => Game.Play(player1, player2, false));
        }
Пример #2
0
        public FitnessInfo Evaluate(IBlackBox phenome)
        {
            double fitness = 0;
            int    winner;
            Player optimalPlayer = new MinMaxPlayer(2, false);
            Player randomPlayer  = new RandomPlayer(2, false);
            Player neatPlayer    = new NEATPlayer(1, true, phenome);

            for (int i = 0; i < 50; i++)
            {
                winner   = Game.Play(neatPlayer, randomPlayer, true);
                fitness += GetScore(winner, neatPlayer.id);
            }

            randomPlayer.id   = 1;
            randomPlayer.turn = true;
            neatPlayer.id     = 2;
            neatPlayer.turn   = false;

            for (int i = 0; i < 50; i++)
            {
                winner   = Game.Play(randomPlayer, neatPlayer, true);
                fitness += GetScore(winner, neatPlayer.id);
            }

            neatPlayer.id   = 1;
            neatPlayer.turn = true;

            winner   = Game.Play(neatPlayer, optimalPlayer, true);
            fitness += GetScore(winner, neatPlayer.id);

            optimalPlayer.id   = 1;
            optimalPlayer.turn = true;
            neatPlayer.id      = 2;
            neatPlayer.turn    = false;

            winner   = Game.Play(optimalPlayer, neatPlayer, true);
            fitness += GetScore(winner, neatPlayer.id);

            evalCount++;

            if (fitness >= 1002)
            {
                stopConditionSatisfied = true;
            }

            return(new FitnessInfo(fitness, fitness));
        }