public void KingValidMovesTest() { Board board = new Board(); var piece = new PieceKing(PieceColor.White); board.LoadPiece("a1", piece); piece.CalculateValidMoves(); Assert.AreEqual(3, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("b1")); Assert.IsTrue(piece.IsValidMove("a2")); Assert.IsTrue(piece.IsValidMove("b2")); board.ClearPieces(); board.LoadPiece("a8", piece); piece.CalculateValidMoves(); Assert.AreEqual(3, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("a7")); Assert.IsTrue(piece.IsValidMove("b7")); Assert.IsTrue(piece.IsValidMove("b8")); board.ClearPieces(); board.LoadPiece("h1", piece); piece.CalculateValidMoves(); Assert.AreEqual(3, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("h2")); Assert.IsTrue(piece.IsValidMove("g1")); Assert.IsTrue(piece.IsValidMove("g2")); board.ClearPieces(); board.LoadPiece("h8", piece); piece.CalculateValidMoves(); Assert.AreEqual(3, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("g8")); Assert.IsTrue(piece.IsValidMove("g7")); Assert.IsTrue(piece.IsValidMove("h7")); board.ClearPieces(); board.LoadPiece("d4", piece); piece.CalculateValidMoves(); Assert.AreEqual(3 + 2 + 3, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("c3")); Assert.IsTrue(piece.IsValidMove("d3")); Assert.IsTrue(piece.IsValidMove("e3")); Assert.IsTrue(piece.IsValidMove("c4")); Assert.IsTrue(piece.IsValidMove("e4")); Assert.IsTrue(piece.IsValidMove("c5")); Assert.IsTrue(piece.IsValidMove("d5")); Assert.IsTrue(piece.IsValidMove("e5")); }
public void RookBasicValidMovesTest() { Board board = new Board(); PieceRook piece = new PieceRook(PieceColor.White); board.LoadPiece("a1", piece); piece.CalculateValidMoves(); Assert.AreEqual(14, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("a8")); Assert.IsTrue(piece.IsValidMove("h1")); board.ClearPieces(); board.LoadPiece("h8", piece); piece.CalculateValidMoves(); Assert.AreEqual(14, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("a8")); Assert.IsTrue(piece.IsValidMove("h1")); board.ClearPieces(); board.LoadPiece("d4", piece); piece.CalculateValidMoves(); Assert.AreEqual(14, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("d1")); Assert.IsTrue(piece.IsValidMove("d8")); Assert.IsTrue(piece.IsValidMove("a4")); Assert.IsTrue(piece.IsValidMove("h4")); }
public void QueenCaptureDiagonalMovesTest() { Board board = new Board(); var whitePiece = new PieceQueen(PieceColor.White); var blackPiece = new PieceQueen(PieceColor.Black); board.LoadPiece("d4", whitePiece); board.LoadPiece("g7", blackPiece); board.LoadPiece("a1", new PieceQueen(PieceColor.White)); whitePiece.CalculateValidMoves(); Assert.AreEqual(3 + 3 + 2 + 3 + 14, whitePiece.GetValidMovesCount()); Assert.IsTrue(whitePiece.IsValidMove("c3")); Assert.IsTrue(whitePiece.IsValidMove("g7")); Assert.IsTrue(whitePiece.IsValidMove("f6")); Assert.IsTrue(whitePiece.IsValidMove("a7")); Assert.IsFalse(whitePiece.IsValidMove("a1")); blackPiece.CalculateValidMoves(); Assert.AreEqual(1 + 3 + 1 + 1 + 14, blackPiece.GetValidMovesCount()); Assert.IsTrue(blackPiece.IsValidMove("h8")); Assert.IsTrue(blackPiece.IsValidMove("d4")); Assert.IsTrue(blackPiece.IsValidMove("f8")); Assert.IsTrue(blackPiece.IsValidMove("h6")); }
public void QueenBasicValidLateralMovesTest() { Board board = new Board(); var piece = new PieceQueen(PieceColor.White); board.LoadPiece("a1", piece); piece.CalculateValidMoves(); Assert.AreEqual(21, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("a8")); Assert.IsTrue(piece.IsValidMove("h1")); board.ClearPieces(); board.LoadPiece("h8", piece); piece.CalculateValidMoves(); Assert.AreEqual(21, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("a8")); Assert.IsTrue(piece.IsValidMove("h1")); board.ClearPieces(); board.LoadPiece("d4", piece); piece.CalculateValidMoves(); Assert.AreEqual(13 + 14, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("d1")); Assert.IsTrue(piece.IsValidMove("d8")); Assert.IsTrue(piece.IsValidMove("a4")); Assert.IsTrue(piece.IsValidMove("h4")); }
public void KnightCaptureMovesTest() { Board board = new Board(); var whitePiece = new PieceKnight(PieceColor.White); var blackPiece = new PieceKnight(PieceColor.Black); board.LoadPiece("d4", whitePiece); board.LoadPiece("f5", blackPiece); board.LoadPiece("c2", new PieceQueen(PieceColor.White)); whitePiece.CalculateValidMoves(); Assert.AreEqual(7, whitePiece.GetValidMovesCount()); Assert.IsFalse(whitePiece.IsValidMove("c2")); Assert.IsTrue(whitePiece.IsValidMove("e2")); Assert.IsTrue(whitePiece.IsValidMove("b3")); Assert.IsTrue(whitePiece.IsValidMove("f3")); Assert.IsTrue(whitePiece.IsValidMove("b5")); Assert.IsTrue(whitePiece.IsValidMove("f5")); Assert.IsTrue(whitePiece.IsValidMove("c6")); Assert.IsTrue(whitePiece.IsValidMove("e6")); blackPiece.CalculateValidMoves(); Assert.AreEqual(8, blackPiece.GetValidMovesCount()); Assert.IsTrue(blackPiece.IsValidMove("e3")); Assert.IsTrue(blackPiece.IsValidMove("g3")); Assert.IsTrue(blackPiece.IsValidMove("h4")); Assert.IsTrue(blackPiece.IsValidMove("d4")); Assert.IsTrue(blackPiece.IsValidMove("h6")); Assert.IsTrue(blackPiece.IsValidMove("d6")); Assert.IsTrue(blackPiece.IsValidMove("e7")); Assert.IsTrue(blackPiece.IsValidMove("g7")); }
public void KingCaptureMovesTest() { Board board = new Board(); var whitePiece = new PieceKing(PieceColor.White); var blackPiece = new PieceKing(PieceColor.Black); board.LoadPiece("d4", whitePiece); board.LoadPiece("e5", blackPiece); board.LoadPiece("e3", new PieceQueen(PieceColor.White)); whitePiece.CalculateValidMoves(); Assert.AreEqual(2 + 2 + 3, whitePiece.GetValidMovesCount()); Assert.IsTrue(whitePiece.IsValidMove("c3")); Assert.IsTrue(whitePiece.IsValidMove("d3")); Assert.IsFalse(whitePiece.IsValidMove("e3")); Assert.IsTrue(whitePiece.IsValidMove("c4")); Assert.IsTrue(whitePiece.IsValidMove("e4")); Assert.IsTrue(whitePiece.IsValidMove("c5")); Assert.IsTrue(whitePiece.IsValidMove("d5")); Assert.IsTrue(whitePiece.IsValidMove("e5")); blackPiece.CalculateValidMoves(); Assert.AreEqual(3 + 2 + 3, blackPiece.GetValidMovesCount()); Assert.IsTrue(blackPiece.IsValidMove("d4")); Assert.IsTrue(blackPiece.IsValidMove("e4")); Assert.IsTrue(blackPiece.IsValidMove("f4")); Assert.IsTrue(blackPiece.IsValidMove("d5")); Assert.IsTrue(blackPiece.IsValidMove("f5")); Assert.IsTrue(blackPiece.IsValidMove("d6")); Assert.IsTrue(blackPiece.IsValidMove("e6")); Assert.IsTrue(blackPiece.IsValidMove("f6")); }
public void BoardConstructorTest() { Board board = new Board(); Assert.IsNotNull(board); Assert.IsNotNull(board['a', '8']); Assert.IsNotNull(board['a', '1']); Assert.IsNotNull(board['h', '8']); Assert.IsNotNull(board["h1"]); Assert.IsNotNull(board['d', '5']); }
public void KnightValidMovesTest() { Board board = new Board(); var piece = new PieceKnight(PieceColor.White); board.LoadPiece("a1", piece); piece.CalculateValidMoves(); Assert.AreEqual(2, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("b3")); Assert.IsTrue(piece.IsValidMove("c2")); board.ClearPieces(); board.LoadPiece("a8", piece); piece.CalculateValidMoves(); Assert.AreEqual(2, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("b6")); Assert.IsTrue(piece.IsValidMove("c7")); board.ClearPieces(); board.LoadPiece("h1", piece); piece.CalculateValidMoves(); Assert.AreEqual(2, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("f2")); Assert.IsTrue(piece.IsValidMove("g3")); board.ClearPieces(); board.LoadPiece("h8", piece); piece.CalculateValidMoves(); Assert.AreEqual(2, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("g6")); Assert.IsTrue(piece.IsValidMove("f7")); board.ClearPieces(); board.LoadPiece("d4", piece); piece.CalculateValidMoves(); Assert.AreEqual(8, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("c2")); Assert.IsTrue(piece.IsValidMove("e2")); Assert.IsTrue(piece.IsValidMove("b3")); Assert.IsTrue(piece.IsValidMove("f3")); Assert.IsTrue(piece.IsValidMove("b5")); Assert.IsTrue(piece.IsValidMove("f5")); Assert.IsTrue(piece.IsValidMove("c6")); Assert.IsTrue(piece.IsValidMove("e6")); }
public void BishopBasicValidMovesTest() { Board board = new Board(); var piece = new PieceBishop(PieceColor.White); board.LoadPiece("a1", piece); piece.CalculateValidMoves(); Assert.AreEqual(7, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("b2")); Assert.IsTrue(piece.IsValidMove("h8")); board.ClearPieces(); board.LoadPiece("a8", piece); piece.CalculateValidMoves(); Assert.AreEqual(7, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("b7")); Assert.IsTrue(piece.IsValidMove("h1")); board.ClearPieces(); board.LoadPiece("h1", piece); piece.CalculateValidMoves(); Assert.AreEqual(7, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("b7")); Assert.IsTrue(piece.IsValidMove("a8")); board.ClearPieces(); board.LoadPiece("h8", piece); piece.CalculateValidMoves(); Assert.AreEqual(7, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("b2")); Assert.IsTrue(piece.IsValidMove("a1")); board.ClearPieces(); board.LoadPiece("d4", piece); piece.CalculateValidMoves(); Assert.AreEqual(13, piece.GetValidMovesCount()); Assert.IsTrue(piece.IsValidMove("a1")); Assert.IsTrue(piece.IsValidMove("h8")); Assert.IsTrue(piece.IsValidMove("a7")); Assert.IsTrue(piece.IsValidMove("g1")); }
public void RookCaptureMovesTest() { Board board = new Board(); PieceRook whitePiece = new PieceRook(PieceColor.White); PieceRook blackPiece = new PieceRook(PieceColor.Black); board.LoadPiece("a1", whitePiece); board.LoadPiece("a7", blackPiece); board.LoadPiece("g1", new PieceRook(PieceColor.White)); whitePiece.CalculateValidMoves(); Assert.AreEqual(5+6, whitePiece.GetValidMovesCount()); Assert.IsTrue(whitePiece.IsValidMove("a7")); Assert.IsFalse(whitePiece.IsValidMove("a8")); Assert.IsFalse(whitePiece.IsValidMove("g1")); Assert.IsTrue(whitePiece.IsValidMove("f1")); blackPiece.CalculateValidMoves(); Assert.AreEqual(1+6+7, blackPiece.GetValidMovesCount()); Assert.IsTrue(blackPiece.IsValidMove("a1")); Assert.IsTrue(blackPiece.IsValidMove("a8")); Assert.IsTrue(blackPiece.IsValidMove("h7")); Assert.IsFalse(blackPiece.IsValidMove("f1")); }
public BoardSquare(Board board, char x, char y) { this.X = x; this.Y = y; this.Board = board; }