Beispiel #1
0
        public static Evaluator GetBestEvaluator(int challengeCount, int gameCount, int maxMoves, Evaluator initialEvaluator = null, int?maxGameTurns = null)
        {
            if (initialEvaluator == null)
            {
                initialEvaluator = Evaluator.GetRandomEvaluator();
            }
            Evaluator champion = initialEvaluator;

            for (int i = 0; i < challengeCount; i++)
            {
                Evaluator challenger = Evaluator.GetRandomEvaluator();

                Player player1         = new Player("Champion", () => new AlphaBetaSearchGameClient(champion, maxMoves));
                Player player2         = new Player("Challenger", () => new AlphaBetaSearchGameClient(challenger, maxMoves));
                var    multiGameServer = new MultiGameServer(player1, player2, gameCount, maxGameTurns);
                multiGameServer.Run();
                if (multiGameServer.WinsPlayer2 > multiGameServer.WinsPlayer1)
                {
                    champion = challenger;
                    Console.Out.WriteLine($"We have a new champion: {champion}");
                }
                else
                {
                    Console.Out.WriteLine($"Current champion won");
                }
            }
            return(champion);
        }
Beispiel #2
0
        static void RunMultiGame()
        {
            Player player1         = new Player("MovePawnsToBase", () => new MovePawnsToBaseGameClient());
            Player player2         = new Player("MovePawnsToKing", () => new MovePawnsToKingGameClient());
            Player player3         = new Player("MoveForward1", () => new MoveForwardGameClient());
            Player player4         = new Player("AlphaBetaSearch1", () => new AlphaBetaSearchGameClient(new Evaluator(0.654, 1.000, 0.125, 0.674, 0.241, 0.346, 0.867, 0.554, 0.338), 6));
            Player player5         = new Player("AlphaBetaSearch2", () => new AlphaBetaSearchGameClient(new Evaluator(1.000, 0.000, 0.043, 0.829, 0.654, 0.082, 0.797, 0.000, 0.437), 6));
            var    multiGameServer = new MultiGameServer(player4, player5, 20, 50, true);

            multiGameServer.Run();
        }
        private double CalculateFitness(Individual individual)
        {
            int wins  = 0;
            int draws = 0;

            foreach (Player opponent in Opponents)
            {
                MultiGameServer multiGameServer = new MultiGameServer(individual.Player, opponent, GameCount, MaxGameTurns, cardDeckGenerator: cardDeckGenerator);
                multiGameServer.Run();
                wins  += multiGameServer.WinsPlayer1;
                draws += multiGameServer.Draws;
            }
            return(GetPlayerScore(wins, draws));
        }