def test_is_empty_space_filled(): """Check that empty spaces are correctly identified. """ board = Board() board.place_stone(position=(3, 3), colour=1) assert not board.is_empty_space(position=(3, 3))
def test_remove_stone_valid(): """Check that the function removes a stone from the board (when there is one present. """ board = Board() board.place_stone(position=(3, 3), colour=1) board.remove_stone(position=(3, 3)) assert board.is_empty_space(position=(3, 3))
def test_place_stone_invalid_position(): """Check that an error is raised if the position is invalid (i.e. lies outside the board). """ n = 4 board = Board(size=n) with pytest.raises(AssertionError): position = (0, 0) board.place_stone(position, colour=1)
def test_is_legal_move_false_one_stone_non_empty_space(): """Check that a one stone move is illegal if the space is not empty. """ board = Board() # Initialise the board with a stone board.place_stone((6, 2), colour=1) move = [(6, 2, 1), ()] assert not board.is_legal_move(move)
def test_place_stone_invalid_non_empty(): """Check that an error is raised if the position is already filled. """ n = 4 board = Board(size=n) position = (6, 0) board.place_stone(position, colour=1) with pytest.raises(AssertionError): board.place_stone(position, colour=1)
def test_place_stone_valid(): """Check that place_stone correctly updates the board state when the placement is valid. """ n = 4 board = Board(size=n) position = (6, 0) board.place_stone(position, colour=1) assert board.board_2d[position[1], position[0]] == 1 assert np.count_nonzero(board.board_2d) == 1
def test_is_legal_move_false_two_stones_two_non_empty_spaces(): """Check that a two stone move is illegal if both of the desired spaces are not empty. """ board = Board() # Initialise the board with a stone board.place_stone((6, 2), colour=1) board.place_stone((6, 3), colour=1) move = [(6, 2, 1), (6, 3, 2)] assert not board.is_legal_move(move)
def test_execute_move_one_capture(): """Check that the function performs correctly for a situation where there is one stone captured. """ board = Board() # Initialise the board with some stones board.place_stone((6, 2), colour=1) board.place_stone((6, 3), colour=3) board.place_stone((5, 4), colour=1) moves = [(5, 3, 2), (4, 4, 1)] board.execute_move(moves, player=0) assert board.board_2d[3, 5] == 2 assert board.board_2d[4, 4] == 1 assert board.captures == [1, 0]
def test_execute_move_no_captures(): """Check that the function performs correctly for a situation where there are no captures. """ board = Board() # Initialise the board with some stones board.place_stone((6, 2), colour=1) board.place_stone((6, 3), colour=3) board.place_stone((5, 4), colour=1) moves = [(5, 3, 3), (4, 4, 4)] board.execute_move(moves, player=1) assert board.board_2d[3, 5] == 3 assert board.board_2d[4, 4] == 4 assert board.captures == [0, 0]
def test_is_fenced_edge(): """Check that the function correctly classifies a fenced bloom at the edge of the board. """ board = Board() # Add a bloom bloom = [(6, 3), (5, 4)] for position in bloom: board.place_stone(position, colour=1) # Fence the bloom for position in bloom: neighbours = board.get_neighbours(position) for neighbour in neighbours: if board.is_empty_space(neighbour): board.place_stone(neighbour, colour=2) assert board.is_fenced(bloom)
def test_get_board_3d(): """Check that the the 2D board representation is successfully converted into a 3D representation. """ board = Board() # Place a few different colour stones on the board board.place_stone(position=(3, 0), colour=1) board.place_stone(position=(6, 0), colour=2) board.place_stone(position=(0, 6), colour=3) board.place_stone(position=(3, 6), colour=4) board_3d = board.get_board_3d() assert board_3d.shape == (4, 7, 7) assert np.count_nonzero(board_3d) == 4 assert board_3d[0, 0, 3] == 1 assert board_3d[1, 0, 6] == 1 assert board_3d[2, 6, 0] == 1 assert board_3d[3, 6, 3] == 1
def test_is_fenced_false(): """Check that the function correctly classifies a non-fenced bloom. """ board = Board() # Add a bloom bloom = [(3, 2), (3, 3), (3, 4), (4, 3)] for position in bloom: board.place_stone(position, colour=1) # Fence the bloom for position in bloom: neighbours = board.get_neighbours(position) for neighbour in neighbours: if board.is_empty_space(neighbour): board.place_stone(neighbour, colour=2) # Remove one of the stones fencing in the bloom board.remove_stone(position=(4, 4)) assert not board.is_fenced(bloom)
def test_find_bloom_members(): """Check that the function correctly identifies all members of a bloom. """ board = Board() # Add a bloom board.place_stone(position=(3, 2), colour=1) board.place_stone(position=(3, 3), colour=1) board.place_stone(position=(3, 4), colour=1) board.place_stone(position=(4, 3), colour=1) # Add an additional neighbouring stone of a different colour (that is not # part of the bloom). board.place_stone(position=(4, 2), colour=2) expected_bloom = [(3, 2), (3, 3), (3, 4), (4, 3)] actual_bloom = board.find_bloom_members(bloom=set(), colour=1, position=(3, 2)) assert len(actual_bloom) == len(expected_bloom) assert set(actual_bloom) == set(expected_bloom)