def test_bishop_can_move_diagonally():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        square = Square.at(3, 5)
        board.set_piece(square, bishop)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        expected_moves = [
            Square.at(0, 2),
            Square.at(1, 3),
            Square.at(2, 4),
            Square.at(4, 6),
            Square.at(5, 7),
            Square.at(1, 7),
            Square.at(2, 6),
            Square.at(4, 4),
            Square.at(5, 3),
            Square.at(6, 2),
            Square.at(7, 1)
        ]
        assert len(moves) == len(expected_moves)
        assert set(moves) == set(expected_moves)
    def test_bishop_can_move_diagonally():

        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        square = Square.at(4, 4)
        board.set_piece(square, bishop)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(6, 6) in moves
    def test_bishop_can_take_opponent():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        square = Square.at(4, 4)
        board.set_piece(square, bishop)
        board.set_piece(Square.at(6, 6), Bishop(Player.BLACK))

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(6, 6) in moves
Example #4
0
    def test_black_bishop_cannot_move_off_top_of_board():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        square = Square.at(1, 7)
        board.set_piece(square, bishop)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(2, 8) not in moves
        assert Square.at(0, 8) not in moves
    def test_bishop_can_move_until_blocked_by_teammate():

        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        square = Square.at(4, 4)
        board.set_piece(square, bishop)
        board.set_piece(Square.at(6, 6), Bishop(Player.WHITE))

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(6, 6) not in moves
Example #6
0
    def test_bishop_can_move_down_and_right():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        bishop_square = Square.at(4, 4)
        board.set_piece(bishop_square, bishop)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(3, 5) in moves
        assert Square.at(2, 6) in moves
        assert Square.at(1, 7) in moves
Example #7
0
    def test_bishop_can_move_up_and_left():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        bishop_square = Square.at(4, 4)
        board.set_piece(bishop_square, bishop)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(5, 3) in moves
        assert Square.at(6, 2) in moves
        assert Square.at(7, 1) in moves
    def test_bishop_cannot_move_off_board():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.BLACK)
        bishop_square = Square.at(4, 4)
        board.set_piece(bishop_square, bishop)

        # Act
        moves = bishop.get_available_moves(board)
        # Assert
        assert Square.at(0, 0) in moves
        assert Square.at(7, 7) in moves
        assert Square.at(8, 8) not in moves
        assert Square.at(-1, -1) not in moves
    def test_bishop_can_move_on_backslash():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.BLACK)
        bishop_square = Square.at(4, 4)
        board.set_piece(bishop_square, bishop)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(3, 5) in moves
        assert Square.at(2, 6) in moves
        assert Square.at(5, 3) in moves
        assert Square.at(6, 2) in moves
Example #10
0
    def test_bishop_cannot_move_through_pieces_down_and_left():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        bishop_square = Square.at(4, 4)
        board.set_piece(bishop_square, bishop)

        friendly = Pawn(Player.WHITE)
        friendly_square = Square.at(3, 3)
        board.set_piece(friendly_square, friendly)
        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(2, 2) not in moves
Example #11
0
    def test_black_bishop_can_move_diagonally():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.BLACK)
        bishop_square = Square.at(3, 3)
        board.set_piece(bishop_square, bishop)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(4, 4) in moves
        assert Square.at(2, 2) in moves
        assert Square.at(4, 2) in moves
        assert Square.at(2, 4) in moves
    def test_bishop_cannot_capture_friendly_pieces():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        square = Square.at(3, 5)
        board.set_piece(square, bishop)

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

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert friendly_square not in moves
    def test_bishop_can_capture_enemy_pieces():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        square = Square.at(3, 5)
        board.set_piece(square, bishop)

        enemy = Pawn(Player.BLACK)
        enemy_square = Square.at(5, 7)
        board.set_piece(enemy_square, enemy)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert enemy_square in moves
Example #14
0
    def test_bishop_cannot_move_off_board():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        bishop_square = Square.at(0, 0)
        board.set_piece(bishop_square, bishop)

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

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert len(moves) == 0
Example #15
0
    def test_bishop_can_capture_down_and_left():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        bishop_square = Square.at(4, 4)
        board.set_piece(bishop_square, bishop)

        enemy = Pawn(Player.BLACK)
        enemy_square = Square.at(2, 2)
        board.set_piece(enemy_square, enemy)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(2, 2) in moves
    def test_bishop_is_blocked_by_enemy_pieces():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        square = Square.at(3, 5)
        board.set_piece(square, bishop)

        enemy = Pawn(Player.BLACK)
        enemy_square = Square.at(5, 3)
        board.set_piece(enemy_square, enemy)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(6, 2) not in moves
    def test_bishop_is_blocked_by_friendly_pieces():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        square = Square.at(3, 5)
        board.set_piece(square, bishop)

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

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert Square.at(6, 2) not in moves
        assert Square.at(7, 7) not in moves
    def test_bishop_cannot_move_if_piece_in_front():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.WHITE)
        bishop_square = Square.at(4, 4)
        board.set_piece(bishop_square, bishop)

        enemy = Pawn(Player.BLACK)
        enemy_square = Square.at(5, 5)
        board.set_piece(enemy_square, enemy)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        print(moves)
        assert Square.at(5, 5) in moves
        assert Square.at(6, 6) not in moves
        assert Square.at(7, 7) not in moves
        assert Square.at(2, 2) in moves
Example #19
0
    def test_black_bishop_cannot_move_if_friendly_piece_in_the_way():
        # Arrange
        board = Board.empty()
        bishop = Bishop(Player.BLACK)
        bishop_square = Square.at(2, 2)
        board.set_piece(bishop_square, bishop)

        obstructing_square1 = Square.at(1, 1)
        obstructing_square2 = Square.at(3, 3)
        obstructing_square3 = Square.at(1, 3)
        obstructing_square4 = Square.at(3, 1)
        obstruction = Pawn(Player.BLACK)
        board.set_piece(obstructing_square1, obstruction)
        board.set_piece(obstructing_square2, obstruction)
        board.set_piece(obstructing_square3, obstruction)
        board.set_piece(obstructing_square4, obstruction)

        # Act
        moves = bishop.get_available_moves(board)

        # Assert
        assert len(moves) == 0