def test_rook_can_move_laterally(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) square = Square.at(2, 5) board.set_piece(square, rook) # Act moves = rook.get_available_moves(board) # Assert expected_moves = [ Square.at(2, 0), Square.at(2, 1), Square.at(2, 2), Square.at(2, 3), Square.at(2, 4), Square.at(2, 6), Square.at(2, 7), Square.at(0, 5), Square.at(1, 5), Square.at(3, 5), Square.at(4, 5), Square.at(5, 5), Square.at(6, 5), Square.at(7, 5) ] assert len(moves) == len(expected_moves) assert set(moves) == set(expected_moves)
def test_white_rook_cannot_move_up_if_pawn_is_adjacent(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) square = Square.at(4, 4) board.set_piece(square, rook) obstructing_square = Square.at(5, 4) obstruction = Pawn(Player.WHITE) board.set_piece(obstructing_square, obstruction) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(5, 4) not in moves @staticmethod def test_white_rook_can_capture(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) square = Square.at(4, 4) board.set_piece(square, rook) obstructing_square = Square.at(5, 4) obstruction = Pawn(Player.BLACK) board.set_piece(obstructing_square, obstruction) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(5, 4) in moves assert Square.at(6, 4) not in moves
def test_white_rooks_cannot_move_if_piece_in_front(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) rook_square = Square.at(4, 4) board.set_piece(rook_square, rook) obstructing_square1 = Square.at(3, 4) obstruction = Pawn(Player.WHITE) board.set_piece(obstructing_square1, obstruction) obstructing_square2 = Square.at(5, 4) obstruction = Pawn(Player.WHITE) board.set_piece(obstructing_square2, obstruction) obstructing_square3 = Square.at(4, 3) obstruction = Pawn(Player.WHITE) board.set_piece(obstructing_square3, obstruction) obstructing_square3 = Square.at(4, 5) obstruction = Pawn(Player.WHITE) board.set_piece(obstructing_square3, obstruction) # Act moves = rook.get_available_moves(board) # Assert assert len(moves) == 0
def test_black_rooks_can_take_white_pieces_but_not_black(): # Arrange board = Board.empty() rook = Rook(Player.BLACK) rook_square = Square.at(4, 4) board.set_piece(rook_square, rook) obstructing_square1 = Square.at(3, 4) obstruction = Pawn(Player.WHITE) board.set_piece(obstructing_square1, obstruction) obstructing_square2 = Square.at(5, 4) obstruction = Pawn(Player.BLACK) board.set_piece(obstructing_square2, obstruction) obstructing_square3 = Square.at(4, 3) obstruction = Pawn(Player.BLACK) board.set_piece(obstructing_square3, obstruction) obstructing_square3 = Square.at(4, 5) obstruction = Pawn(Player.WHITE) board.set_piece(obstructing_square3, obstruction) # Act moves = rook.get_available_moves(board) # Assert assert len(moves) == 2
def test_black_rook_cannot_move_off_top_of_board(): # Arrange board = Board.empty() rook = Rook(Player.BLACK) square = Square.at(0, 7) board.set_piece(square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(0, 8) not in moves
def test_white_rook_can_move_multiple_squares_horizonally(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) square = Square.at(4, 4) board.set_piece(square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(4, 6) in moves
def test_white_rook_can_move_up_one_square(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) square = Square.at(1, 4) board.set_piece(square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(2, 4) in moves
def test_rook_can_take_opponent(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) square = Square.at(4, 4) board.set_piece(square, rook) board.set_piece(Square.at(6, 4), Rook(Player.BLACK)) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(6, 4) in moves
def test_rook_can_move_straight(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) square = Square.at(4, 4) board.set_piece(square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(6, 4) in moves
def test_rook_can_move_until_blocked_by_teammate(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) square = Square.at(4, 4) board.set_piece(square, rook) board.set_piece(Square.at(6, 4), Rook(Player.WHITE)) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(6, 4) not in moves
def test_rook_cannot_move_off_board(): # Arrange board = Board.empty() rook = Rook(Player.BLACK) rook_square = Square.at(4, 4) board.set_piece(rook_square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(0, 4) in moves assert Square.at(7, 4) in moves assert Square.at(8, 4) not in moves assert Square.at(-1, 4) not in moves
def test_white_rooks_can_move_horizontally_right(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) square = Square.at(0, 0) board.set_piece(square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(0, 1) in moves assert Square.at(0, 5) in moves
def test_rooks_can_move_right(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) rook_square = Square.at(3, 4) board.set_piece(rook_square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(3, 5) in moves assert Square.at(3, 6) in moves assert Square.at(3, 7) in moves
def test_black_rooks_can_move_vertically_down(): # Arrange board = Board.empty() rook = Rook(Player.BLACK) square = Square.at(7, 7) board.set_piece(square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(1, 7) in moves assert Square.at(5, 7) in moves
def test_white_rooks_can_move_vertically_up(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) square = Square.at(0, 0) board.set_piece(square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(1, 0) in moves assert Square.at(5, 0) in moves
def test_black_rooks_can_move_horizontally_left(): # Arrange board = Board.empty() rook = Rook(Player.BLACK) square = Square.at(7, 7) board.set_piece(square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(7, 1) in moves assert Square.at(7, 5) in moves
def test_rook_can_move_horizontally(): # Arrange board = Board.empty() rook = Rook(Player.BLACK) rook_square = Square.at(4, 4) board.set_piece(rook_square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(4, 5) in moves assert Square.at(4, 6) in moves assert Square.at(4, 3) in moves assert Square.at(4, 2) in moves
def test_black_rook_can_move_vertically_and_horizontally(): # Arrange board = Board.empty() rook = Rook(Player.BLACK) rook_square = Square.at(1, 5) board.set_piece(rook_square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(1, 4) in moves assert Square.at(4, 5) in moves assert Square.at(0, 5) in moves assert Square.at(1, 6) in moves
def test_white_rook_can_move_vertically_and_horizontally(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) rook_square = Square.at(1, 3) board.set_piece(rook_square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(1, 4) in moves assert Square.at(4, 3) in moves assert Square.at(0, 3) in moves assert Square.at(1, 1) in moves
def test_rook_can_move_vertically(): # Arrange board = Board.empty() rook = Rook(Player.BLACK) rook_square = Square.at(4, 4) board.set_piece(rook_square, rook) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(5, 4) in moves assert Square.at(6, 4) in moves assert Square.at(3, 4) in moves assert Square.at(2, 4) in moves
def test_white_rook_cannot_move_if_white_piece_in_front(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) rook_square = Square.at(0, 0) board.set_piece(rook_square, rook) obstructing_square = Square.at(1, 0) obstruction = Pawn(Player.WHITE) board.set_piece(obstructing_square, obstruction) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(1, 0) not in moves
def test_rooks_cannot_move_left_through_pieces(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) rook_square = Square.at(4, 4) board.set_piece(rook_square, rook) enemy_1 = Pawn(Player.BLACK) enemy_1_square = Square.at(4, 3) board.set_piece(enemy_1_square, enemy_1) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(4, 2) not in moves
def test_rooks_can_capture_right(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) rook_square = Square.at(4, 4) board.set_piece(rook_square, rook) enemy_1 = Pawn(Player.BLACK) enemy_1_square = Square.at(4, 6) board.set_piece(enemy_1_square, enemy_1) # Act moves = rook.get_available_moves(board) # Assert assert Square.at(4, 6) in moves
def test_rooks_cannot_move_off_the_board(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) rook_square = Square.at(0, 0) board.set_piece(rook_square, rook) friendly_1 = Pawn(Player.WHITE) friendly_1_square = Square.at(1, 0) board.set_piece(friendly_1_square, friendly_1) friendly_2 = Pawn(Player.WHITE) friendly_2_square = Square.at(0, 1) board.set_piece(friendly_2_square, friendly_2) # Act moves = rook.get_available_moves(board) # Assert assert len(moves) == 0
def test_rook_cannot_move_if_piece_in_front(): # Arrange board = Board.empty() rook = Rook(Player.WHITE) rook_square = Square.at(4, 4) board.set_piece(rook_square, rook) enemy = Pawn(Player.BLACK) enemy_square = Square.at(5, 4) board.set_piece(enemy_square, enemy) # Act moves = rook.get_available_moves(board) # Assert print(moves) assert Square.at(5, 4) in moves assert Square.at(6, 4) not in moves assert Square.at(7, 4) not in moves assert Square.at(2, 4) in moves
def test_black_rook_cannot_move_if_friendly_piece_in_front_or_next_to(): # Arrange board = Board.empty() rook = Rook(Player.BLACK) rook_square = Square.at(2, 2) board.set_piece(rook_square, rook) obstructing_square1 = Square.at(2, 1) obstructing_square2 = Square.at(1, 2) obstructing_square3 = Square.at(2, 3) obstructing_square4 = Square.at(3, 2) 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 = rook.get_available_moves(board) # Assert assert len(moves) == 0