当前位置: 首页>>代码示例>>C#>>正文


C# GameState.PlayGameToEnd方法代码示例

本文整理汇总了C#中Dominion.GameState.PlayGameToEnd方法的典型用法代码示例。如果您正苦于以下问题:C# GameState.PlayGameToEnd方法的具体用法?C# GameState.PlayGameToEnd怎么用?C# GameState.PlayGameToEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Dominion.GameState的用法示例。


在下文中一共展示了GameState.PlayGameToEnd方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetHumanReadableGameLog

        public string GetHumanReadableGameLog(int gameNumber)
        {
            // swap order every game if needed
            int[] playedPositions = this.GetPlayerOrderForGameNumber(gameNumber);

            var stringWriter = new System.IO.StringWriter();
            var textWriter = new IndentedTextWriter(stringWriter);
            var readableLog = new HumanReadableGameLog(textWriter);
            var gainSequenceLog = new GainSequenceGameLog(textWriter);
            Random random = new Random(gameNumber);
            using (Game game = new Game(random, gameConfig, new GameLogMultiplexer(readableLog, gainSequenceLog)))
            {
                GameState gameState = new GameState(
                    playerActions,
                    playedPositions,
                    game);
                gameState.PlayGameToEnd();
            }

            return stringWriter.ToString();
        }
开发者ID:NathanTeeuwen,项目名称:Dominulator,代码行数:21,代码来源:StrategyComparison.cs

示例2: ComparePlayers

        public StrategyComparisonResults ComparePlayers(
            GetLogForGame getHumanReadableLogWriter = null,
            GetLogForGame getDebugLogWriter = null,
            bool shouldParallel = true,
            bool gatherStats = true,
            CreateGameLog createGameLog = null,
            int randomSeed = 0)
        {
            PlayerAction player1 = playerActions[0];
            PlayerAction player2 = playerActions[1];

            var result = new StrategyComparisonResults(this, gatherStats);

            Action<int> loopBody = delegate(int gameCount)
            {
                System.Threading.Interlocked.Increment(ref totalGameCount);
                using (IndentedTextWriter textWriter = getHumanReadableLogWriter != null ? getHumanReadableLogWriter(gameCount) :  null)
                using (IndentedTextWriter debugWriter = getDebugLogWriter != null ? getDebugLogWriter(gameCount) : null)
                {
                    var gameLogs = new List<IGameLog>();
                    if (gatherStats)
                    {
                        gameLogs.Add(result.statGatherer);
                    }
                    if (createGameLog != null)
                    {
                        gameLogs.Add(createGameLog());
                    }
                    if (textWriter != null)
                    {
                        var humanReadableGameLog = new HumanReadableGameLog(textWriter);
                        gameLogs.Add(humanReadableGameLog);
                        var gainSequenceGameLog = new GainSequenceGameLog(textWriter);
                        gameLogs.Add(gainSequenceGameLog);
                    }
                    if (debugWriter != null)
                    {
                        var debugLog = new DebugGameLog(debugWriter);
                        gameLogs.Add(debugLog);
                        var gainSequenceGameLog = new GainSequenceGameLog(debugWriter);
                        gameLogs.Add(gainSequenceGameLog);
                    }

                    var gameLogMultiplexer = new GameLogMultiplexer(gameLogs.ToArray());

                    // swap order every game if needed
                    int[] playedPositions = this.GetPlayerOrderForGameNumber(gameCount);

                    Random random = new Random(gameCount + randomSeed);
                    using (Game game = new Game(random, gameConfig, gameLogMultiplexer))
                    {

                        GameState gameState = new GameState(
                            playerActions,
                            playedPositions,
                            game);

                        gameState.PlayGameToEnd();
                        PlayerState[] winners = gameState.WinningPlayers;

                        int player1Score = gameState.players.OriginalPlayerOrder[playedPositions[0]].TotalScore();
                        int player2Score = gameState.players.OriginalPlayerOrder[playedPositions[1]].TotalScore();
                        int scoreDifference = player2Score - player1Score;

                        lock (result)
                        {
                            result.pointSpreadHistogramData.AddOneToBucket(scoreDifference);
                            result.gameEndOnTurnHistogramData.AddOneToBucket(gameState.players.CurrentPlayer.TurnNumber);
                            result.maxTurnNumber = Math.Max(gameState.players.CurrentPlayer.TurnNumber, result.maxTurnNumber);
                            if (winners.Length == 1)
                            {
                                int winningPlayerIndex = winners[0].Actions == player1 ? 0 : 1;
                                result.winnerCount[winningPlayerIndex]++;
                            }
                            else
                            {
                                result.tieCount++;
                            }
                        }
                    }
                }
            };

            if (shouldParallel)
            {
                Parallel.ForEach(Enumerable.Range(0, numberOfGames), loopBody);
            }
            else
            {
                for (int gameCount = 0; gameCount < numberOfGames; ++gameCount)
                    loopBody(gameCount);
            }

            result.gameEndOnTurnHistogramData.InitializeAllBucketsUpTo(result.maxTurnNumber);

            return result;
        }
开发者ID:NathanTeeuwen,项目名称:Dominulator,代码行数:97,代码来源:StrategyComparison.cs


注:本文中的Dominion.GameState.PlayGameToEnd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。