Beispiel #1
0
        internal StrategyComparisonResults GetResultsFor(ComparisonDescription descr)
        {
            StrategyComparisonResults result = null;

            if (!this.resultsCache.TryGetValue(descr, out result))
            {
                GameConfigBuilder builder       = new GameConfigBuilder();
                PlayerAction      playerAction1 = descr.Player1Action;
                PlayerAction      playerAction2 = descr.Player2Action;

                if (playerAction1 != null && playerAction2 != null)
                {
                    System.Console.WriteLine("Playing {0} vs {1}", playerAction1.PlayerName, playerAction2.PlayerName);
                    PlayerAction.SetKingdomCards(builder, new PlayerAction[] { playerAction1, playerAction2 });

                    var gameConfig = builder.ToGameConfig();

                    var strategyComparison = new StrategyComparison(playerAction1, playerAction2, gameConfig, rotateWhoStartsFirst: true, numberOfGames: 1000);
                    result = strategyComparison.ComparePlayers(
                        gameIndex => null,
                        gameIndex => null,
                        shouldParallel: true,
                        gatherStats: true);

                    this.resultsCache.Add(descr, result);
                }
                else
                {
                    this.resultsCache.Add(descr, null);
                }
            }

            return(result);
        }
Beispiel #2
0
        public double ComparePlayers(
            PlayerAction[] playerActions,
            GameConfig gameConfig,
            bool rotateWhoStartsFirst   = true,
            bool shouldParallel         = true,
            bool showVerboseScore       = true,
            bool showCompactScore       = false,
            bool showDistribution       = false,
            bool createHtmlReport       = true,
            bool createRankingReport    = false,
            int numberOfGames           = 1000,
            int logGameCount            = 100,
            bool debugLogs              = false,
            CreateGameLog createGameLog = null)
        {
            var strategyComparison = new StrategyComparison(playerActions, gameConfig, rotateWhoStartsFirst, numberOfGames);
            var results            = strategyComparison.ComparePlayers(
                gameIndex => gameIndex < logGameCount ? GetGameLogWriterForIteration(playerActions, gameIndex) : null,
                gameIndex => debugLogs && gameIndex < logGameCount ? GetDebugLogWriterForIteration(playerActions, gameIndex) : null,
                shouldParallel: shouldParallel,
                gatherStats: createHtmlReport,
                createGameLog: createGameLog);

            if (showVerboseScore)
            {
                results.WriteVerboseScore(System.Console.Out);
            }

            if (showCompactScore)
            {
                results.WriteCompactScore(System.Console.Out);
            }

            if (showDistribution)
            {
                results.ShowDistribution(System.Console.Out);
            }

            if (createHtmlReport)
            {
                deferredHtmlGenerator.AddResults(results, GetOutputFilename);
            }

            if (createRankingReport)
            {
                this.resultRanker.AddResult(playerActions[0].PlayerName, playerActions[1].PlayerName, results.WinDifference);
            }


            return(results.WinDifference);
        }