Exemplo n.º 1
0
    def test_board_equivalence(self):
        size = 9
        cache = BitBoardCache("../cache/9-magics", size=9, win_chain_length=5, force_build_win_checks=False)
        bitboard = BitBoard(cache, size=9, win_chain_length=5)

        normal_board = Board(size=9, win_chain_length=5)

        fboard_1 = FeatureBoard_v1_1(bitboard)
        fboard_2 = FeatureBoard_v1_1(normal_board)

        for i in range(1000):
            if np.random.rand() < 0.5:
                normal_board.make_random_move()
                bitboard.move(normal_board.get_last_move())
                if normal_board.game_over():
                    break
                fboard_1.move(normal_board.get_last_move())
                fboard_2.move(normal_board.get_last_move())
            elif normal_board.get_last_move():
                normal_board.unmove()
                bitboard.unmove()
                fboard_1.unmove()
                fboard_2.unmove()
            self.verify_sync(normal_board, fboard_2)
            self.verify_sync(bitboard, fboard_1)
Exemplo n.º 2
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())