def test_board_create(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) assert board.tiles() == tiles assert board.entangl_tiles() == []
def test_win_option_some_winners(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) coll_moves = ['x3', 'x1', 'x5', 'y2', '-', 'y4', 'y6', 'x7', 'y8'] assert board.win_options(coll_moves) == (['x1'], [[0, 1, 2]])
def main(): tiles = [] for i in range(0, 9): tiles.append(Tile()) myboard = Board(tiles) game = Game(myboard) game.play()
def test_is_not_game_end(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) assert game.is_game_end() is False
def test_is_winner_no_end(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) board.tiles()[0].set_collapsed('x1') assert board.is_winner() == (None, [])
def test_could_collapse_error(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) with pytest.raises(InvalidCollapseError): board.could_collapse(1, 'x1')
def test_win_option_no_winner(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) coll_moves = ['x1', 'x3', 'y2', '-', '-', '-', '-', '-', '-'] assert board.win_options(coll_moves) == ([], [])
def test_add_entangle_tile(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) assert board.entangl_tiles() == [] board.add_entangl_tile(1) assert board.entangl_tiles() == [1]
def test_clear_tile(): tile = Tile(['x1'], True, True) assert tile.array() == ['x1'] assert tile.is_collapsed() is True assert tile.is_entanglement() is True tile.clear_tile() assert tile.array() == [] assert tile.is_entanglement() is False
def test_bot_create_easy(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) bot = Bot('easy', board, game) assert bot.mode() == 'easy'
def test_move_wrong_number(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) with pytest.raises(InvalidMoveError): game.move(9)
def test_move_correct(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) assert game.move(1) == 1 assert game.last_tile() == 1
def test_is_winner_one_option(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) board.tiles()[0].set_collapsed('x1') board.tiles()[1].set_collapsed('x3') board.tiles()[2].set_collapsed('x5') assert board.is_winner() == ('x', [0, 1, 2])
def test_move_is_not_correct_collapsed_tile(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) tile = game.board.tiles()[1] tile.set_collapsed('x1') assert game.move_is_correct(tile, 1) is False
def test_whos_move_x(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) game.set_last_move('y1') game.increase_counter() assert game.whos_move() == 'x2'
def test_reset_entangle_tiles(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) board.add_entangl_tile(1) board.add_entangl_tile(2) assert board.entangl_tiles() == [1, 2] board.reset_entangl_tiles() assert board.entangl_tiles() == []
def test_could_collapse(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) board.add_entangl_tile(1) board.add_entangl_tile(2) board.tiles()[1].set_move_on_tile('x1') board.tiles()[2].set_move_on_tile('x1') assert board.could_collapse(1, 'x1') is True
def test_is_game_end(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) board.tiles()[0].set_collapsed('x1') board.tiles()[1].set_collapsed('x3') board.tiles()[2].set_collapsed('x5') game = Game(board) assert game.is_game_end() is True
def test_move_is_not_correct_same_tile(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) game.set_first_move(False) game.set_last_tile(1) tile = game.board.tiles()[1] assert game.move_is_correct(tile, 1) is False
def test_bot_move(monkeypatch): def one(a): return 1 tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) bot = Bot('easy', board, game) monkeypatch.setattr('quantum_tictactoe.bot.choice', one) assert bot.move() == (1, 1)
def test_is_winner_more_options(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) board.tiles()[0].set_collapsed('x7') board.tiles()[1].set_collapsed('x3') board.tiles()[2].set_collapsed('x5') board.tiles()[3].set_collapsed('y2') board.tiles()[4].set_collapsed('y4') board.tiles()[5].set_collapsed('y6') assert board.is_winner() == ('y', [3, 4, 5])
def test_analyse_board(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) board.add_entangl_tile(1) board.add_entangl_tile(2) board.tiles()[1].set_move_on_tile('x1') board.tiles()[2].set_move_on_tile('x1') board.tiles()[1].set_move_on_tile('y2') board.tiles()[2].set_move_on_tile('y2') board.collapse(1, 'x1') assert board.analyse_board() == ['-', 'x1', 'y2', '-', '-', '-', '-', '-', '-']
def test_is_game_end_more_options(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) board.tiles()[0].set_collapsed('x7') board.tiles()[1].set_collapsed('x3') board.tiles()[2].set_collapsed('x5') board.tiles()[3].set_collapsed('y2') board.tiles()[4].set_collapsed('y4') board.tiles()[5].set_collapsed('y6') game = Game(board) assert game.is_game_end() is True
def test_is_not_entanglement(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) board.tiles()[1].set_move_on_tile('x1') board.tiles()[2].set_move_on_tile('x1') board.tiles()[1].set_move_on_tile('x3') board.tiles()[3].set_move_on_tile('x3') game.set_last_move('x3') game.set_last_tile(1) assert game.is_entanglement() is False
def test_collapse_error(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) board.add_entangl_tile(1) board.add_entangl_tile(2) board.tiles()[1].set_move_on_tile('x1') board.tiles()[1].set_move_on_tile('x3') board.tiles()[2].set_move_on_tile('x1') board.tiles()[1].set_move_on_tile('y2') board.tiles()[2].set_move_on_tile('y2') with pytest.raises(InvalidCollapseError): board.collapse(1, 'x3')
def test_game_create(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) assert game.board == board assert game.entanglement is False assert game.basic is True assert game.is_first_move() is True assert game.last_tile() == '' assert game.last_move() == '' assert game.is_finished() is False assert game.game_result() == '' assert game.counter() == 1
def test_game_making_changes(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) game.set_first_move(False) assert game.is_first_move() is False game.set_last_tile(2) assert game.last_tile() == 2 game.set_last_move('x1') assert game.last_move() == 'x1' game.set_finished() assert game.is_finished() is True game.increase_counter() assert game.counter() == 2
def test_game_entanglement(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) assert game.entanglement is False assert game.basic is True board.tiles()[1].set_move_on_tile('x1') board.tiles()[2].set_move_on_tile('x1') board.tiles()[1].set_move_on_tile('x3') board.tiles()[2].set_move_on_tile('x3') game.set_last_move('x3') game.set_last_tile(2) game.game_entanglement() assert game.entanglement is True assert game.basic is False
def test_game_clear(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) game.set_first_move(False) game.set_last_tile(2) game.set_last_move('x1') game.set_finished() game.increase_counter() game.clear_game() assert game.is_first_move() is True assert game.last_tile() == '' assert game.last_move() == '' assert game.is_finished() is False assert game.game_result() == '' assert game.counter() == 1
def test_game_collapse_bot(): tiles = [] for _ in range(9): tiles.append(Tile()) board = Board(tiles) game = Game(board) bot = Bot('easy', board, game) assert board.tiles()[1].is_collapsed() is False assert board.tiles()[2].is_collapsed() is False board.tiles()[1].set_move_on_tile('x1') board.tiles()[2].set_move_on_tile('x1') board.tiles()[1].set_move_on_tile('x3') board.tiles()[2].set_move_on_tile('x3') game.set_last_move('x3') game.set_last_tile(2) game.game_entanglement() game.game_collapse(bot, 'easy') assert board.tiles()[1].is_collapsed() is True assert board.tiles()[2].is_collapsed() is True