Skip to content

Commit

Permalink
Added scramble on reset
Browse files Browse the repository at this point in the history
  • Loading branch information
DoubleGremlin181 committed Jun 10, 2020
1 parent 87ee903 commit 4708b3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion rubiks_cube_gym/envs/rubiks_cube_222.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pickle

import random
import gym
from gym import spaces
import os
Expand Down Expand Up @@ -36,6 +36,23 @@ def update_cube_reduced(self):
def update_cube_state(self):
self.cube_state = self.cube_states[self.cube_reduced]

def generate_scramble(self):
scramble_len = 0
prev_move = None
scramble = ""
moves = ['F', 'R', 'U']
move_type = ['', '2', "'"]

while scramble_len < 10:
move = random.choice(moves)
while move == prev_move:
move = random.choice(moves)
scramble += move + random.choice(move_type) + " "
prev_move = move
scramble_len += 1

return scramble[:-1]

def move(self, move_side, move_type=None):
repetitions = {None: 1, "2": 2, "'": 3} # TODO Optimize prime moves from 3 clockwise to 1 anticlockwise moves

Expand Down Expand Up @@ -97,6 +114,8 @@ def reset(self, scramble=None):
dtype=np.uint8)
if scramble:
self.algorithm(scramble)
else:
self.algorithm(self.generate_scramble())

self.update_cube_reduced()
self.update_cube_state()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
long_description = f.read()

setup(name='rubiks_cube_gym',
version='0.0.5',
version='0.0.6',
url="https://github.com/DoubleGremlin181/RubiksCubeGym/",
description="OpenAI Gym environments for various twisty puzzles",
long_description=long_description,
Expand Down

0 comments on commit 4708b3d

Please sign in to comment.