Esempio n. 1
0
def test_tile_position_lists_on_thin_board():
    board = Board([[], [], [], []])

    white_tiles, black_tiles = board.tile_position_lists()

    assert not white_tiles
    assert not black_tiles
Esempio n. 2
0
def test_tile_position_lists_on_1x1_board():
    board = Board([[TileTypes.EMPTY]])

    white_tiles, black_tiles = board.tile_position_lists()

    assert not white_tiles
    assert not black_tiles
Esempio n. 3
0
def test_tile_position_lists_on_empty_board():
    board = Board([])

    white_tiles, black_tiles = board.tile_position_lists()

    assert not white_tiles
    assert not black_tiles
Esempio n. 4
0
def test_tile_position_lists_returns_deque():
    board = Board([[]])

    white_tiles, black_tiles = board.tile_position_lists()

    assert type(white_tiles) is deque
    assert type(black_tiles) is deque
Esempio n. 5
0
    def __init__(self, array_board):
        # an instance of the Board class generated from the input array
        self._board = Board(array_board)
        # a deque of SearchPositions (all white tiles)
        self._white_tiles = None
        # a deque of SearchPositions (all black tiles)
        self._black_tiles = None
        # the maximum number of rounds required to reach a black tile
        self._max_rounds = 0

        self._initialize_game()
        self._simulate_game()
Esempio n. 6
0
class Gone():
    def __init__(self, array_board):
        # an instance of the Board class generated from the input array
        self._board = Board(array_board)
        # a deque of SearchPositions (all white tiles)
        self._white_tiles = None
        # a deque of SearchPositions (all black tiles)
        self._black_tiles = None
        # the maximum number of rounds required to reach a black tile
        self._max_rounds = 0

        self._initialize_game()
        self._simulate_game()

    def _initialize_game(self):
        self._white_tiles, self._black_tiles = self._board.tile_position_lists(
        )

    def _simulate_game(self):
        # While self._white_tiles is not empty
        while self._white_tiles:
            # Let tile be the first element in _white_tiles
            # Remove tile from _white_tiles
            tile = self._white_tiles.popleft()

            self._add_neighbors_to_next_round(tile)

            self._max_rounds = max(self._max_rounds, tile.round)

    def _add_neighbors_to_next_round(self, tile):
        # Let neighbors contain the valid SearchPositions adjacent to tile
        neighbors = tile.neighbors()

        for neighbor_position in neighbors:
            if self._board.tile_at(neighbor_position) == TileTypes.BLACK:
                neighbor_position.increment_round()
                self._board.flip_tile(neighbor_position)
                # Add neighbor_position to end of _white_tiles
                self._white_tiles.append(neighbor_position)

    def max_rounds(self):
        return self._max_rounds

    def any_black_remaining(self):
        for position in self._black_tiles:
            if self._board.tile_at(position) == TileTypes.BLACK:
                return True

        # If none found, return False
        return False
Esempio n. 7
0
def _generate_basic_test_board():
    board = _numbers_to_tile_types([
        [1, 1, 1],
        [2, 2, 2],
        [3, 3, 3]
    ])
    return board, Board(board)
Esempio n. 8
0
def test_init_stores_input_board():
    input_board, _ = _generate_basic_test_board()

    board = Board(input_board)

    assert board._board is input_board
Esempio n. 9
0
def test_tile_position_lists_on_bad_data():
    board = Board(None)

    with pytest.raises(TypeError):
        board.tile_position_lists()