本文整理汇总了C#中GameBoard.GetTokens方法的典型用法代码示例。如果您正苦于以下问题:C# GameBoard.GetTokens方法的具体用法?C# GameBoard.GetTokens怎么用?C# GameBoard.GetTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameBoard
的用法示例。
在下文中一共展示了GameBoard.GetTokens方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GameBoard_GetTokens
public void GameBoard_GetTokens()
{
int rows = 6;
int cols = 6;
var props = new GameProperties(new Bounds(rows, cols), 2, 2);
var tokens = new[] { new Token(1, "player1", TokenType.Flag, 1, 2), new Token(1, "player2", TokenType.Flag, 3, 4) };
var gameBoard = new GameBoard(props, tokens);
CollectionAssert.AreEquivalent(tokens.OrderBy(x => x.Row).ThenBy(x => x.Col).ToArray(),
gameBoard.GetTokens().OrderBy(x => x.Row).ThenBy(x => x.Col).ToArray(),
"GetTokens should return an equivelant collection to input collection");
}
示例2: GetNextMove
public GameMove GetNextMove(GameBoard gameBoard, Player player)
{
// most naive AI ever
var random = Core.Utility.Random.New();
var validTokens = gameBoard.GetTokens()
.Where(x => x.PlayerID == player.ID && x.IsMovable())
.Select(x => new { Token = x, Moves = gameBoard.GetValidMoves(x).ToList() })
.Where(x => x.Moves.Any())
.ToList();
if (!validTokens.Any())
{
throw new Exceptions.InvalidMoveException("No available moves for player " + player.Name + ".");
}
var token = validTokens[random.Next(validTokens.Count)];
var point = token.Moves[random.Next(token.Moves.Count)];
return new GameMove(token.Token, point);
}