本文整理汇总了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);
}