Example #1
0
 public StrategyComparisonResults(StrategyComparison comparison, bool gatherStats)
 {
     this.comparison                 = comparison;
     this.statGatherer               = gatherStats ? new StatsPerTurnGameLog(comparison.NumberOfPlayers, comparison.gameConfig.cardGameSubset) : null;
     this.winnerCount                = new int[comparison.NumberOfPlayers];
     this.tieCount                   = 0;
     this.maxTurnNumber              = -1;
     this.pointSpreadHistogramData   = new HistogramData();
     this.gameEndOnTurnHistogramData = new HistogramData();
 }
 public StrategyComparisonResults(StrategyComparison comparison, bool gatherStats)
 {
     this.comparison = comparison;
     this.statGatherer = gatherStats ? new StatsPerTurnGameLog(comparison.NumberOfPlayers, comparison.gameConfig.cardGameSubset) : null;
     this.winnerCount = new int[comparison.NumberOfPlayers];
     this.tieCount = 0;
     this.maxTurnNumber = -1;
     this.pointSpreadHistogramData = new HistogramData();
     this.gameEndOnTurnHistogramData = new HistogramData();
 }
Example #3
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;
        }
Example #4
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);
                    builder.SetKingdomCards(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;
        }