Ejemplo n.º 1
0
        /// <summary>
        /// Returns the win percentage of the first controller
        /// </summary>
        public static double CompareAiControllers(GameInstance game, List <DNA> dnas, IMobController c1,
                                                  IMobController c2)
        {
            game.AssignAiControllers(c1, c2);
            int redWins    = 0;
            int totalGames = 0;

            foreach (var dna in dnas)
            {
                GameSetup.OverrideGameDna(game, dna, dna);

                GameSetup.ResetGameAndPositions(game);
                var r1 = Playout(game, c1, c2);

                GameSetup.ResetGameAndPositions(game);
                var r2 = Playout(game, c2, c1);

                redWins += r1.RedWins;
                redWins += r2.BlueWins;

                Debug.Assert(r1.RedWins + r1.BlueWins <= 1);
                Debug.Assert(r2.RedWins + r2.BlueWins <= 1);

                totalGames += 2;
            }

            return((double)redWins / (double)totalGames);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs a playout with the given encounter defined by a DNA pair and both controllers.
        /// </summary>
        public static int Playout(GameInstance game, DNA d1, DNA d2, IMobController c1, IMobController c2)
        {
            GameSetup.OverrideGameDna(game, d1, d2);

            game.AssignAiControllers(c1, c2);

            int iterations = Constants.MaxPlayoutEvaluationIterations;

            var hub = new GameEventHub(game);

            while (!game.IsFinished && iterations-- > 0)
            {
                game.CurrentController.FastPlayTurn(hub);
                ActionEvaluator.FNoCopy(game, UctAction.EndTurnAction());
            }

            if (Constants.GetLogBuffer().ToString().Length != 0)
            {
                Console.WriteLine(Constants.GetLogBuffer());
            }
            Constants.ResetLogBuffer();

            return(Constants.MaxPlayoutEvaluationIterations - iterations);
        }