Exemplo n.º 1
0
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'
Exemplo n.º 2
0
 def play(self):
     """
     Main loop of the game in terminal version
     """
     bot_selected = False
     while not bot_selected:
         try:
             bot_mode = input('Choose bot mode (none/easy/hard): ')
             bot = Bot(bot_mode, self.board, self)
             bot_selected = True
         except BotTypeError as err:
             print(err)
     while not self._finished:
         while self.basic:
             try:
                 if bot_mode != 'none' and 'x' in self._last_move:
                     self._last_tile = bot.move()[1]
                     self._last_move = self.whos_move()
                     self._counter += 1
                     self.game_entanglement()
                 else:
                     if self._first_move:
                         print(self.board.show_board())
                         new_move = int(
                             input(f'Your move {self.whos_move()[0]}: '))
                         self.move(new_move)
                         self._first_move = False
                     else:
                         print(self.board.show_board())
                         new_move = int(
                             input(f'Your move {self.whos_move()[0]}: '))
                         self.move(new_move)
                         self._last_move = self.whos_move()
                         self._counter += 1
                         self._first_move = True
                         self.game_entanglement()
             except InvalidMoveError as err:
                 print(err)
             except ValueError:
                 print("Don't use letters. Use digits from 0 to 8.")
         if self.entanglement:
             try:
                 print(self.board.show_board())
                 who_choose = 'X' if 'y' in self._last_move else 'Y'
                 if bot_mode == 'none' or who_choose == 'X':
                     description = f'Player {who_choose} choose'
                     description += ' what will collapse(tile_number,what_collapse): '
                     collapse = input(description)
                     self.game_collapse(bot, bot_mode, collapse)
                 else:
                     self.game_collapse(bot, bot_mode)
                 self.board.reset_entangl_tiles()
             except InvalidCollapseError as err:
                 print(err)
         self.is_game_end()
     print(self.board.show_board())
     print(self._game_result)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
def test_bot_collapse(monkeypatch):
    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()[2].set_move_on_tile('x3')
    board.add_entangl_tile(1)
    board.add_entangl_tile(2)
    bot = Bot('easy', board, game)

    def one(a):
        return 1

    monkeypatch.setattr('quantum_tictactoe.bot.choice', one)
    assert bot.collapse() == '1,x3'
Exemplo n.º 5
0
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