Пример #1
0
 def test_chain_length(self):
     board = Board(size=9, win_chain_length=4)
     self.assertEqual(board.get_spot_coord(0, 0), Player.NONE)
     board.move_coord(0, 0)
     self.assertEqual(board.get_spot_coord(0, 0), Player.FIRST)
     self.assertFalse(board.is_move_available(0))
     board.move_coord(0, 1)
     board.move_coord(1, 1)
     self.assertEqual(board.get_spot_coord(1, 1), Player.FIRST)
     index00 = board._transformer.coordinate_to_index(0, 0)
     index11 = board._transformer.coordinate_to_index(1, 1)
     assert (board.chain_length(index11, -1, 0) == 1)
     assert (board.chain_length(index11, -1, -1) == 2)
     assert (board.chain_length(index00, 1, 1) == 2)
     board.move_coord(1, 0)
     board.move_coord(2, 2)
     board.move_coord(2, 3)
     board.move_coord(3, 3)
     board.unmove()
     board.move_coord(3, 3)
     index33 = board._transformer.coordinate_to_index(3, 3)
     self.assertEqual(board.chain_length(index33, 1, 1), 1)
     self.assertEqual(board.get_spot_coord(2, 2), Player.FIRST)
     assert (board.game_won())
Пример #2
0
        if board.get_player_to_move() == Board.FIRST_PLAYER:
            inp = input("Input your move (i.e. \"3 5\"): ")
            if len(inp.split(' ')) != 2:
                print('Incorrect number of coordinates, please try again!')
                continue
            x, y = inp.split(' ')
            try:
                x = int(x)
                y = int(y)
            except:
                print('Please input Numbers!')
                continue
            if x < 0 or x >= SIZE or y < 0 or y >= SIZE:
                print('Out of bounds!')
                continue
            if not board.is_move_available(x, y):
                print('Invalid Move!')
                continue
            result = board.move(x, y)
            print(board.guide_print())
        else:
            print('Computer is thinking...')

            possible_moves, root_node = mind.p_search(board,
                                                      False,
                                                      root_node=None,
                                                      save_root=False)

            best_move, best_node = possible_moves[0]
            print(" ")
            print(best_move, 'Q:', best_node.q)