Esempio n. 1
0
 def test_mass_play(self):
     for i in range(1000):
         board = Board(size=7, win_chain_length=4)
         board.make_random_move()
         if board.game_over():
             self.assertTrue(board.game_won() or board.game_assume_drawn())
         if board.game_assume_drawn():
             self.assertTrue(board.game_over())
Esempio n. 2
0
    def test_thoughtboard_root_win(self):
        trivial_board = Board(size=9, win_chain_length=5)
        trivial_board.set_to_one_move_from_win()
        tb = ThoughtBoard(trivial_board, FeatureBoard_v1_1)

        trivial_board.move(36)
        print(trivial_board.pprint())
        move_list = MoveList((), []).append(36)
        self.assertTrue(trivial_board.game_won())
        self.assertTrue(tb.game_over_after(move_list))
Esempio n. 3
0
    def test_odd_board_bug(self):
        board = Board(size=9, win_chain_length=5)

        board.move_coord(4, 0)
        board.move_coord(4, 1)
        board.move_coord(3, 0)
        board.move_coord(3, 1)
        board.move_coord(2, 0)
        board.move_coord(2, 1)
        board.move_coord(1, 0)
        board.move_coord(1, 1)
        board.move_coord(0, 0)
        self.assertTrue(board.game_won())
Esempio n. 4
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())
Esempio n. 5
0
            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)

            if best_node.q > PExpNode.MAX_MODEL_Q:
                print('Computer Resigns!')
                break

            board.move(*best_move)
            print(board.guide_print())

        if board.game_approx_drawn():
            print("DRAW!")
            break

        if board.game_won():
            if board.get_player_to_move() == 1:
                print('COMPUTER WINS!')
            else:
                print('YOU WIN!')
            break