本文整理汇总了C#中GameBoard.GetValidMoves方法的典型用法代码示例。如果您正苦于以下问题:C# GameBoard.GetValidMoves方法的具体用法?C# GameBoard.GetValidMoves怎么用?C# GameBoard.GetValidMoves使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameBoard
的用法示例。
在下文中一共展示了GameBoard.GetValidMoves方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: GameBoard_Test_GetValidMoves
public void GameBoard_Test_GetValidMoves()
{
int rows = 3;
int cols = 3;
int rowsPerPlayer = 1;
int bombsPerPlayer = 1;
var tokens = new List<Token>
{
/*
* |_|F1|_|
* |_|R1|_|
* |_|F2|_|
*/
new Token(1, "p1", TokenType.Flag, new Point(0, 1)),
new Token(2, "p1", TokenType.Rock, new Point(1, 1)),
new Token(3, "p2", TokenType.Flag, new Point(2, 1))
};
var playerToken = tokens[1];
var board = new GameBoard(
properties: new GameProperties(new Bounds(rows, cols), rowsPerPlayer, bombsPerPlayer),
tokens: tokens);
var points = board.GetValidMoves(playerToken).OrderBy(x => x.X).ThenBy(x => x.Y).ToList();
Assert.AreEqual(3, points.Count, "Number of moves should be correct");
Assert.AreEqual(new Point(1, 0), points[0], "First point should be correct");
Assert.AreEqual(new Point(1, 2), points[1], "Second point should be correct");
Assert.AreEqual(new Point(2, 1), points[2], "Third point should be correct");
}