public void TestBlackPawn() { IBoardBuilder boardBuilder = new BoardBuilder(); IBoard board = boardBuilder.Columns(8).Rows(8).AddPiece(new Piece(PieceType.PAWN, new BoardPosition(0, 7), this.blackPlayer)).Build(); IPieceMovementStrategies pms = new ClassicPieceMovementStrategies(); Assert.True(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(0, 7))).GetPossibleMoves(board).Contains(new BoardPosition(0, 6))); Assert.True(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(0, 7))).GetPossibleMoves(board).Contains(new BoardPosition(0, 5))); Assert.False(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(0, 7))).GetPossibleMoves(board).Contains(new BoardPosition(0, 4))); }
public void TestBishop() { IBoardBuilder boardBuilder = new BoardBuilder(); IBoard board = boardBuilder.Columns(8).Rows(8).AddPiece(new Piece(PieceType.BISHOP, new BoardPosition(1, 1), this.whitePlayer)).Build(); IPieceMovementStrategies pms = new ClassicPieceMovementStrategies(); Assert.False(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(1, 1))).GetPossibleMoves(board).Contains(new BoardPosition(1, 1))); Assert.True(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(1, 1))).GetPossibleMoves(board).Contains(new BoardPosition(7, 7))); Assert.True(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(1, 1))).GetPossibleMoves(board).Contains(new BoardPosition(0, 0))); Assert.False(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(1, 1))).GetPossibleMoves(board).Contains(new BoardPosition(7, 0))); Assert.True(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(1, 1))).GetPossibleMoves(board).Contains(new BoardPosition(5, 5))); Assert.False(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(1, 1))).GetPossibleMoves(board).Contains(new BoardPosition(1, 4))); }
public void TestKnight() { IBoardBuilder boardBuilder = new BoardBuilder(); IBoard board = boardBuilder .Columns(8) .Rows(8) .AddPiece(new Piece(PieceType.KNIGHT, new BoardPosition(3, 3), this.whitePlayer)) .Build(); IPieceMovementStrategies pms = new ClassicPieceMovementStrategies(); Assert.False(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(3, 3))).GetPossibleMoves(board).Contains(new BoardPosition(3, 5))); Assert.True(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(3, 3))).GetPossibleMoves(board).Contains(new BoardPosition(1, 4))); Assert.False(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(3, 3))).GetPossibleMoves(board).Contains(new BoardPosition(1, 5))); }
public void TestQueenCaptureAndMovement() { IBoardBuilder boardBuilder = new BoardBuilder(); IBoard board = boardBuilder.Columns(8).Rows(8) .AddPiece(new Piece(PieceType.QUEEN, new BoardPosition(0, 0), this.whitePlayer)) .AddPiece(new Piece(PieceType.ROOK, new BoardPosition(2, 0), this.blackPlayer)) .Build(); IPieceMovementStrategies pms = new ClassicPieceMovementStrategies(); //Test that the queen can eat the rook Assert.True(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(0, 0))).GetPossibleMoves(board).Contains(new BoardPosition(2, 0))); //But cant go past it Assert.False(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(0, 0))).GetPossibleMoves(board).Contains(new BoardPosition(3, 0))); }
public void TestBlackPawnsCapture() { IBoardBuilder boardBuilder = new BoardBuilder(); IBoard board = boardBuilder.Columns(8).Rows(8) .AddPiece(new Piece(PieceType.PAWN, new BoardPosition(1, 6), this.blackPlayer)) .AddPiece(new Piece(PieceType.ROOK, new BoardPosition(1, 5), this.whitePlayer)) .AddPiece(new Piece(PieceType.ROOK, new BoardPosition(0, 5), this.whitePlayer)) .Build(); IPieceMovementStrategies pms = new ClassicPieceMovementStrategies(); //Test that the pawn can eat the rook on the left Assert.True(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(1, 6))).GetPossibleMoves(board).Contains(new BoardPosition(0, 5))); //But cant capture the one in front of it Assert.False(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(1, 6))).GetPossibleMoves(board).Contains(new BoardPosition(1, 5))); //And cant also go past it with the double movement Assert.False(pms.PieceMovementStrategy(board.GetPieceAtPosition(new BoardPosition(1, 6))).GetPossibleMoves(board).Contains(new BoardPosition(1, 4))); }