コード例 #1
0
def reset_env():
    ## Set Parameters ##
    side = SIDE
    n_moves = N_MOVES
    ####################

    return cube.CubeObject(side, n_moves)
コード例 #2
0
ファイル: unitTests.py プロジェクト: sekharcvs/RubiksCube
def checkCheckEquivalentStates():
    # multiple rotations and reverse rotations lead to the same place
    n_moves = 25
    count = 0
    count_match = 0
    for side in range(1, 10):
        for _ in range(100):
            C = cube.CubeObject(dim=side, n_moves=n_moves)
            state1 = C.state
            C = cube.CubeObject(dim=side, n_moves=n_moves)
            state2 = C.state

            count = count + 1
            if cube.check_equivalent_states(state1, state2) is True:
                count_match = count_match + 1

    percMatch = (100.0 * count_match) / count
    return percMatch, count_match, count
コード例 #3
0
ファイル: unitTests.py プロジェクト: sekharcvs/RubiksCube
def checkMoveReversability():
    diff = True
    for side in range(1, 10):
        for n_moves in range(1, 20):
            C = cube.CubeObject(dim=side, n_moves=n_moves)
            C.apply_moves(cube.get_inverse_moves(C.moves_list))
            if cube.isSolved(C.state) is False:
                diff = False
                break
    return diff
コード例 #4
0
ファイル: unitTests.py プロジェクト: sekharcvs/RubiksCube
def checkRotationalMoveEquivalence():
    n_moves = 10
    diff = True

    for side in range(2, 4):
        C = cube.CubeObject(side, n_moves=n_moves)
        state0 = C.state
        states_list = C.states_list
        moves_list = C.moves_list
        for iter in range(80):
            moves0 = cube.get_random_moves(side, n_moves)
            state1, _, _ = cube.moves_shuffle(state0, side, moves0,
                                              np.zeros([0, 3]).astype(np.int),
                                              np.zeros([0, 6, side, side]))
            moves1 = cube.get_random_moves(side, 1)
            move1 = moves1[0]

            a = np.zeros([0, 3]).astype(np.int)
            b = np.zeros([0, 6, side, side])
            state1_moved, _, _ = cube.moves_shuffle(state1, side, moves1, a, b)

            for a in range(3):
                for d in [-1, 1]:
                    for t in range(1, 4):
                        state2 = cube.rotate_cube(state1, a, d * t)
                        move2 = cube.get_move_axis_turns(move1, side, a, d * t)
                        moves2 = move2.reshape(1, 3)
                        move1_ = cube.get_move_axis_turns(move1, side, a, 0)
                        if (move1 == move1_) is False:
                            _ = 1
                        state2_moved, _, _ = cube.moves_shuffle(
                            state2, side, moves2,
                            np.zeros([0, 3]).astype(np.int),
                            np.zeros([0, 6, side, side]))

                        # state1 = np.load('temp1.npy')
                        # state2 = np.load('temp2.npy')

                        w = cube.check_equivalent_states(state1, state2)
                        x = cube.check_equivalent_states(
                            state1_moved, state2_moved)
                        y = not cube.check_exact_equal_arrays(
                            state1, state1_moved)
                        z = not cube.check_exact_equal_arrays(
                            state2, state2_moved)
                        if (w and x and y and z) is False:
                            # np.save('temp1.npy', state1)
                            # np.save('temp2.npy', state2)
                            diff = False
                            break
    return diff
コード例 #5
0
ファイル: unitTests.py プロジェクト: sekharcvs/RubiksCube
def checkRotations():
    # multiple rotations and reverse rotations lead to the same place
    n_moves = 10
    diff = True
    rotations = np.zeros(12).astype(np.int)
    rotations[0:4] = 0
    rotations[4:8] = 1
    rotations[8:12] = 2

    rotations_orig = np.repeat(rotations, 4)

    for side in range(1, 10):
        for _ in range(10):
            rotations = np.random.permutation(rotations_orig)
            C = cube.CubeObject(dim=side, n_moves=n_moves)
            state1 = C.state
            for a in rotations:
                C.rotate_cube(a, 1)
                if cube.check_equivalent_states(state1, C.state) is False:
                    diff = False
                    break
    return diff
コード例 #6
0
model_name = "Q_Network_2STEP_20000_episodes.pickle"

total_count = np.zeros([n_moves_high - n_moves_low + 1])
solved_count = np.zeros([n_moves_high - n_moves_low + 1])

model = q_network.get_q_network_obj(model_name)

total_states = 0
seen_states = 0
for i in range(1000):
    if n_moves_high > n_moves_low:
        n_moves = np.random.randint(n_moves_low, n_moves_high + 1)
    else:
        n_moves = n_moves_low

    C1 = cube.CubeObject(dim=side, n_moves=n_moves)
    #cube.display(C1.state, C1.side, C1.colormap)

    total_count[n_moves - n_moves_low] = total_count[n_moves - n_moves_low] + 1

    j = 0
    while (cube.isSolved(C1.state) is False) and (j < 3):
        obs = (C1.state).astype(np.int)
        moves_encodings, does_state_exist = q_netowrk_solver.q_network_step(
            obs, model)

        total_states = total_states + 1
        if does_state_exist is True:
            seen_states = seen_states + 1

        moves = cube.decode_moves(moves_encodings, side)