Ejemplo n.º 1
0
    def test_en_passant():
        # Arrange
        board = Board.empty()
        defending_pawn = Pawn(Player.WHITE)
        defending_pawn_square_1 = Square.at(1, 4)
        board.set_piece(defending_pawn_square_1, defending_pawn)

        attacking_pawn = Pawn(Player.BLACK)
        attacking_pawn_square_1 = Square.at(3, 5)
        board.set_piece(attacking_pawn_square_1, attacking_pawn)

        # Act
        defending_pawn_moves_1 = defending_pawn.get_available_moves(board)

        defending_pawn_square_2 = Square.at(3, 4)

        # Assert
        assert defending_pawn_square_2 in defending_pawn_moves_1

        board.move_piece(defending_pawn_square_1, defending_pawn_square_2)

        attacking_pawn_moves_1 = attacking_pawn.get_available_moves(board)

        en_passant_square = Square.at(2, 4)

        assert en_passant_square in attacking_pawn_moves_1

        board.move_piece(attacking_pawn_square_1, en_passant_square)

        assert board.get_piece(defending_pawn_square_2) is None
Ejemplo n.º 2
0
    def test_black_pawn_changes_to_queen_when_moved_to_top_of_board():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.BLACK)
        square = Square.at(1, 4)
        board.set_piece(square, pawn)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert len(moves) == 1
Ejemplo n.º 3
0
    def test_black_pawn_cannot_move_at_bottom_of_board():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.BLACK)
        square = Square.at(0, 4)
        board.set_piece(square, pawn)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert len(moves) == 0
Ejemplo n.º 4
0
    def test_white_pawns_can_move_up_one_square():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.WHITE)
        square = Square.at(1, 4)
        board.set_piece(square, pawn)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert Square.at(2, 4) in moves
Ejemplo n.º 5
0
    def test_black_pawn_can_move_down_two_squares_if_not_moved():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.BLACK)
        square = Square.at(6, 4)
        board.set_piece(square, pawn)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert Square.at(4, 4) in moves
Ejemplo n.º 6
0
    def test_white_pawn_cannot_move_at_top_of_board():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.WHITE)
        square = Square.at(7, 4)
        board.set_piece(square, pawn)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert len(moves) == 0
Ejemplo n.º 7
0
    def test_black_pawn_cannot_move_down_two_squares_if_already_moved():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.BLACK)
        starting_square = Square.at(6, 4)
        board.set_piece(starting_square, pawn)

        intermediate_square = Square.at(5, 4)
        pawn.move_to(board, intermediate_square)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert Square.at(3, 4) not in moves
Ejemplo n.º 8
0
    def test_white_pawn_cannot_move_up_two_squares_if_already_moved():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.WHITE)
        starting_square = Square.at(1, 4)
        board.set_piece(starting_square, pawn)

        intermediate_square = Square.at(2, 4)
        pawn.move_to(board, intermediate_square)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert Square.at(4, 4) not in moves
Ejemplo n.º 9
0
    def test_white_pawn_cannot_move_if_piece_in_front():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.WHITE)
        pawn_square = Square.at(4, 4)
        board.set_piece(pawn_square, pawn)

        obstructing_square = Square.at(5, 4)
        obstruction = Pawn(Player.BLACK)
        board.set_piece(obstructing_square, obstruction)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert len(moves) == 0
Ejemplo n.º 10
0
    def test_black_pawn_cannot_move_two_squares_if_piece_one_in_front():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.BLACK)
        pawn_square = Square.at(6, 4)
        board.set_piece(pawn_square, pawn)

        obstructing_square = Square.at(5, 4)
        obstruction = Pawn(Player.WHITE)
        board.set_piece(obstructing_square, obstruction)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert Square.at(4, 4) not in moves
Ejemplo n.º 11
0
    def test_black_pawns_can_capture_diagonally():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.BLACK)
        pawn_square = Square.at(3, 4)
        board.set_piece(pawn_square, pawn)

        friendly = Pawn(Player.BLACK)
        friendly_square = Square.at(2, 5)
        board.set_piece(friendly_square, friendly)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert Square.at(2, 3) not in moves
        assert Square.at(2, 5) not in moves
Ejemplo n.º 12
0
    def test_white_pawns_cannot_move_diagonally_except_to_capture():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.WHITE)
        pawn_square = Square.at(3, 4)
        board.set_piece(pawn_square, pawn)

        friendly = Pawn(Player.WHITE)
        friendly_square = Square.at(4, 5)
        board.set_piece(friendly_square, friendly)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert Square.at(4, 3) not in moves
        assert Square.at(4, 5) not in moves
Ejemplo n.º 13
0
    def test_pawn_can_en_passant():
        # Arrange
        board = Board.empty()
        pawn1 = Pawn(Player.WHITE)
        pawn1_square = Square.at(1, 4)
        board.set_piece(pawn1_square, pawn1)
        pawn1_to_square = Square.at(3, 4)

        pawn2 = Pawn(Player.BLACK)
        pawn2_square = Square.at(3, 5)
        board.set_piece(pawn2_square, pawn2)

        # Act
        board.move_piece(pawn1_square, pawn1_to_square)
        moves = pawn2.get_available_moves(board)

        # Assert
        assert Square.at(2, 4) in moves
        assert Square.at(2, 5) in moves
        assert Square.at(2, 6) not in moves
Ejemplo n.º 14
0
    def test_black_pawn_can_be_captured_by_en_pessant():
        # Arrange
        board = Board.empty()

        pawn1 = Pawn(Player.BLACK)  # MAKE BLACK PAWN
        starting_square1 = Square.at(6, 4)
        board.set_piece(starting_square1, pawn1)

        pawn2 = Pawn(Player.WHITE)  # MAKE WHITE PAWN
        starting_square2 = Square.at(4, 3)
        board.set_piece(starting_square2, pawn2)

        intermediate_square = Square.at(4, 4)  # move black pawn
        pawn1.move_to(board, intermediate_square)

        # Act
        moves = pawn2.get_available_moves(board)

        # Assert
        assert Square.at(5, 4) in moves
Ejemplo n.º 15
0
    def test_black_pawns_can_capture_diagonally():
        # Arrange
        board = Board.empty()
        pawn = Pawn(Player.BLACK)
        pawn_square = Square.at(3, 4)
        board.set_piece(pawn_square, pawn)

        enemy1 = Pawn(Player.WHITE)
        enemy1_square = Square.at(2, 5)
        board.set_piece(enemy1_square, enemy1)

        enemy2 = Pawn(Player.WHITE)
        enemy2_square = Square.at(2, 3)
        board.set_piece(enemy2_square, enemy2)

        # Act
        moves = pawn.get_available_moves(board)

        # Assert
        assert enemy1_square in moves
        assert enemy2_square in moves