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


C# IPlayer.ReceiveTurn方法代码示例

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


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

示例1: PlayGame

        public static void PlayGame(IPlayer blackPlayer, IPlayer whitePlayer)
        {
            gameRecord.AppendLine("(;FF[4]GM[1]SZ[9]AP[dotNetGo]");

            gameRecord.AppendLine(String.Format("PB[{0}]", blackPlayer.Name));
            gameRecord.AppendLine("HA[0]");
            gameRecord.AppendLine(String.Format("PW[{0}]", whitePlayer.Name));
            gameRecord.AppendLine("KM[6.5]");
            gameRecord.AppendLine("RU[Chinese]");
            gameRecord.AppendLine("");
            gameRecord.AppendLine("");
            Board board = new Board();
            while (board.IsGameOver() == false)
            {
                Move move;
                switch (board.ActivePlayer)
                {
                    case 1:
                        move = blackPlayer.GetMove();
                        break;
                    default: //case 2:
                        move = whitePlayer.GetMove();
                        break;
                }
                if (blackPlayer.ReceiveTurn(move) == false)
                    throw new ImpossibleException("somehow invalid turn made it through", "PlayGame");
                if (whitePlayer.ReceiveTurn(move) == false)
                    throw new ImpossibleException("somehow invalid turn made it through", "PlayGame");
                if (move.row >= 0 && move.column >= 0)
                    gameRecord.AppendFormat(";{0}[{1}{2}]", board.ActivePlayer == 1? "B": "W", alphabet[move.column], alphabet[move.row]);
                if (board.PlaceStone(move) == false)
                    throw new ImpossibleException("somehow invalid turn made it through", "PlayGame");
                Console.WriteLine(board);
                //Console.ReadLine();
            }
            switch (board.State)
            {
                case Board.GameState.BlackSurrendered:
                    Console.WriteLine("White won by resignation, last position:");
                    break;
                case Board.GameState.WhiteSurrendered:
                    Console.WriteLine("Black won by resignation, last position:");
                    break;
                case Board.GameState.DoublePass:
                    double blackScore, whiteScore;
                    board.DetermineWinner(out blackScore, out whiteScore);
                    gameRecord.AppendFormat(";RE[{0}+{1}]", blackScore > whiteScore?"B":"W", Math.Abs(blackScore-whiteScore));
                    Console.WriteLine(board);
                    Console.WriteLine("Turn: {0}", board.TurnNumber);
                    Console.WriteLine("Black score: {0}; White score: {1}", blackScore, whiteScore);
                    Console.WriteLine("last position:");
                    break;
            }
            Console.WriteLine(board);
            gameRecord.Append(")");
            DateTime dt = DateTime.Now;
            string filename = String.Format("{0}-{1}-{2}-{3}-{4}-{5}.sgf",
                dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second);
            File.WriteAllText(filename, gameRecord.ToString(), Encoding.UTF8);
        }
开发者ID:drunklurker,项目名称:dotNetGo,代码行数:60,代码来源:Program.cs


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