本文整理汇总了C#中ChessGame.GetValidMoves方法的典型用法代码示例。如果您正苦于以下问题:C# ChessGame.GetValidMoves方法的具体用法?C# ChessGame.GetValidMoves怎么用?C# ChessGame.GetValidMoves使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ChessGame
的用法示例。
在下文中一共展示了ChessGame.GetValidMoves方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGetValidMovesBlackQueen
public static void TestGetValidMovesBlackQueen()
{
ChessPiece[][] board = new ChessPiece[8][]
{
new[] { o, o, o, o, kw, o, kb, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, qb, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o }
};
ChessGame cb = new ChessGame(board, Player.Black);
ReadOnlyCollection<Move> actual = cb.GetValidMoves(new Position(File.D, Rank.Four));
List<Move> expected = new List<Move>()
{
new Move("D4", "D1", Player.Black),
new Move("D4", "D2", Player.Black),
new Move("D4", "D3", Player.Black),
new Move("D4", "D5", Player.Black),
new Move("D4", "D6", Player.Black),
new Move("D4", "D7", Player.Black),
new Move("D4", "D8", Player.Black),
new Move("D4", "A4", Player.Black),
new Move("D4", "B4", Player.Black),
new Move("D4", "C4", Player.Black),
new Move("D4", "E4", Player.Black),
new Move("D4", "F4", Player.Black),
new Move("D4", "G4", Player.Black),
new Move("D4", "H4", Player.Black),
new Move("D4", "A1", Player.Black),
new Move("D4", "B2", Player.Black),
new Move("D4", "C3", Player.Black),
new Move("D4", "E5", Player.Black),
new Move("D4", "F6", Player.Black),
new Move("D4", "G7", Player.Black),
new Move("D4", "H8", Player.Black),
new Move("D4", "G7", Player.Black),
new Move("D4", "F6", Player.Black),
new Move("D4", "E5", Player.Black),
new Move("D4", "C3", Player.Black),
new Move("D4", "B2", Player.Black),
new Move("D4", "A1", Player.Black)
};
Assert.AreEqual(expected.Count, actual.Count);
foreach (Move move in expected)
{
Assert.True(actual.Contains(move), "Actual does not contain " + move.ToString());
}
}
示例2: TestGetValidMovesBlackKnight
public static void TestGetValidMovesBlackKnight()
{
ChessPiece[][] board = new ChessPiece[8][]
{
new[] { o, o, o, kw, o, kb, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, nb, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o }
};
ChessGame cb = new ChessGame(board, Player.Black);
ReadOnlyCollection<Move> actual = cb.GetValidMoves(new Position(File.D, Rank.Four));
List<Move> expected = new List<Move>()
{
new Move("D4", "C2", Player.Black),
new Move("D4", "B3", Player.Black),
new Move("D4", "C6", Player.Black),
new Move("D4", "B5", Player.Black),
new Move("D4", "E2", Player.Black),
new Move("D4", "E6", Player.Black),
new Move("D4", "F3", Player.Black),
new Move("D4", "F5", Player.Black)
};
Assert.AreEqual(expected.Count, actual.Count);
foreach (Move move in expected)
{
Assert.True(actual.Contains(move), "Actual does not contain " + move.ToString());
}
}
示例3: TestGetValidMovesBlackStartingPosition
public static void TestGetValidMovesBlackStartingPosition()
{
ChessGame cb = new ChessGame();
cb.ApplyMove(new Move(new Position(File.A, Rank.Two), new Position(File.A, Rank.Three), Player.White), true);
ReadOnlyCollection<Move> actual = cb.GetValidMoves(Player.Black);
List<Move> expected = new List<Move>()
{
new Move("A7", "A6", Player.Black),
new Move("A7", "A5", Player.Black),
new Move("B7", "B6", Player.Black),
new Move("B7", "B5", Player.Black),
new Move("C7", "C6", Player.Black),
new Move("C7", "C5", Player.Black),
new Move("D7", "D6", Player.Black),
new Move("D7", "D5", Player.Black),
new Move("E7", "E6", Player.Black),
new Move("E7", "E5", Player.Black),
new Move("F7", "F6", Player.Black),
new Move("F7", "F5", Player.Black),
new Move("G7", "G6", Player.Black),
new Move("G7", "G5", Player.Black),
new Move("H7", "H6", Player.Black),
new Move("H7", "H5", Player.Black),
new Move("B8", "A6", Player.Black),
new Move("B8", "C6", Player.Black),
new Move("G8", "F6", Player.Black),
new Move("G8", "H6", Player.Black)
};
Assert.AreEqual(expected.Count, actual.Count);
foreach (Move move in expected)
{
Assert.True(actual.Contains(move), "Actual does not contain " + move.ToString());
}
}
示例4: TestGetValidMovesWhiteStartingPosition
public static void TestGetValidMovesWhiteStartingPosition()
{
ChessGame cb = new ChessGame();
ReadOnlyCollection<Move> actual = cb.GetValidMoves(Player.White);
List<Move> expected = new List<Move>()
{
new Move("A2", "A3", Player.White),
new Move("A2", "A4", Player.White),
new Move("B2", "B3", Player.White),
new Move("B2", "B4", Player.White),
new Move("C2", "C3", Player.White),
new Move("C2", "C4", Player.White),
new Move("D2", "D3", Player.White),
new Move("D2", "D4", Player.White),
new Move("E2", "E3", Player.White),
new Move("E2", "E4", Player.White),
new Move("F2", "F3", Player.White),
new Move("F2", "F4", Player.White),
new Move("G2", "G3", Player.White),
new Move("G2", "G4", Player.White),
new Move("H2", "H3", Player.White),
new Move("H2", "H4", Player.White),
new Move("B1", "A3", Player.White),
new Move("B1", "C3", Player.White),
new Move("G1", "F3", Player.White),
new Move("G1", "H3", Player.White)
};
Assert.AreEqual(expected.Count, actual.Count);
foreach (Move move in expected)
{
Assert.True(actual.Contains(move), "Actual does not contain " + move.ToString());
}
}
示例5: TestGetValidMovesBlackPawnPromotion
public static void TestGetValidMovesBlackPawnPromotion()
{
Piece[][] board = new Piece[8][]
{
new[] { kw, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, kb, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, pb },
new[] { o, o, o, o, o, o, o, o }
};
ChessGame cb = new ChessGame(board, Player.Black);
ReadOnlyCollection<Move> actual = cb.GetValidMoves(new Position(File.H, 2));
List<Move> expected = new List<Move>()
{
new Move("H2", "H1", Player.Black, 'q'),
new Move("H2", "H1", Player.Black, 'R'),
new Move("H2", "H1", Player.Black, 'N'),
new Move("H2", "H1", Player.Black, 'b')
};
Assert.AreEqual(expected.Count, actual.Count);
foreach (Move move in expected)
{
Assert.True(actual.Contains(move), "Actual does not contain " + move.ToString());
}
}
示例6: TestGetValidMovesWhitePawn
public static void TestGetValidMovesWhitePawn()
{
Piece[][] board = new Piece[8][]
{
new[] { kw, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o },
new[] { o, o, o, kb, o, o, o, o },
new[] { pb, o, pb, o, o, o, o, o },
new[] { o, pw, o, o, o, o, o, o },
new[] { o, o, o, o, o, o, o, o }
};
ChessGame cb = new ChessGame(board, Player.White);
ReadOnlyCollection<Move> actual = cb.GetValidMoves(new Position(File.B, 2));
List<Move> expected = new List<Move>()
{
new Move("B2", "B3", Player.White),
new Move("B2", "B4", Player.White),
new Move("B2", "A3", Player.White),
new Move("B2", "C3", Player.White)
};
Assert.AreEqual(expected.Count, actual.Count);
foreach (Move move in expected)
{
Assert.True(actual.Contains(move), "Actual does not contain " + move.ToString());
}
}