Skip to content

Commit

Permalink
Added new methods for Skewb and Pyraminx
Browse files Browse the repository at this point in the history
  • Loading branch information
DoubleGremlin181 committed Jul 2, 2020
1 parent f3b434d commit 8975f0d
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Currently available environments:
| Actions | L, R, U, B |
| Rewards | (-inf, 100] |
| Max steps | 250 |
| Reward Types | Base |
| Reward Types | Base, Layer by Layer Method |
| Render Modes | 'human', 'rgb_array', 'ansi' |

### Skewb
Expand All @@ -47,7 +47,7 @@ Currently available environments:
| Actions | L, R, U, B |
| Rewards | (-inf, 100] |
| Max steps | 250 |
| Reward Types | Base |
| Reward Types | Base, Sarah's Method(Advanced) |
| Render Modes | 'human', 'rgb_array', 'ansi' |

## Installation
Expand Down
12 changes: 12 additions & 0 deletions rubiks_cube_gym/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@
max_episode_steps=250,
)

register(
id='pyraminx-wo-tips-lbl-v0',
entry_point='rubiks_cube_gym.envs:PyraminxWoTipsEnvLBL',
max_episode_steps=250,
)

register(
id='skewb-v0',
entry_point='rubiks_cube_gym.envs:SkewbEnv',
max_episode_steps=250,
)

register(
id='skewb-sarah-v0',
entry_point='rubiks_cube_gym.envs:SkewbEnvSarah',
max_episode_steps=250,
)
2 changes: 2 additions & 0 deletions rubiks_cube_gym/envs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
from rubiks_cube_gym.envs.rubiks_cube_222_lbl import RubiksCube222EnvLBL
from rubiks_cube_gym.envs.rubiks_cube_222_ortega import RubiksCube222EnvOrtega
from rubiks_cube_gym.envs.pyraminx_wo_tips import PyraminxWoTipsEnv
from rubiks_cube_gym.envs.pyraminx_wo_tips_lbl import PyraminxWoTipsEnvLBL
from rubiks_cube_gym.envs.skewb import SkewbEnv
from rubiks_cube_gym.envs.skewb_sarah import SkewbEnvSarah
51 changes: 51 additions & 0 deletions rubiks_cube_gym/envs/pyraminx_wo_tips_lbl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from rubiks_cube_gym.envs.pyraminx_wo_tips import PyraminxWoTipsEnv
import numpy as np
from operator import itemgetter


class PyraminxWoTipsEnvLBL(PyraminxWoTipsEnv):
def __init__(self):
super(PyraminxWoTipsEnvLBL, self).__init__()
self.FL = None
self.OLL = None

def check_FL(self):
for pos in FL_POS:
if itemgetter(*pos)(self.cube_reduced) == itemgetter(*pos)("RRRRRGBBBBBRRRGGGBBBRGGGGGBYYYYYYYYY"):
return True
return False

def check_solved(self):
if self.cube_reduced == "RRRRRGBBBBBRRRGGGBBBRGGGGGBYYYYYYYYY":
return True

def reward(self):
reward = -40 * self.FL
done = False

if self.check_FL():
reward += 40
self.FL = True
else:
self.FL = False

if self.check_solved():
reward += 60
done = True

if reward <= 0:
reward -= 1

return reward, done

def reset(self, scramble=None):
super(PyraminxWoTipsEnvLBL, self).reset(scramble=scramble)
self.FL = self.check_FL()

return self.cube_state


FL_POS = [[0, 1, 2, 3, 4, 11, 12, 13, 20, 5, 14, 15, 20, 21, 6, 7, 8, 9, 10, 27, 28, 32, 33, 35],
[5, 14, 15, 16, 21, 22, 23, 24, 25, 3, 4, 12, 13, 20, 6, 7, 17, 18, 26, 27, 28, 29, 30, 31],
[6, 7, 8, 9, 10, 17, 18, 19, 26, 5, 15, 16, 24, 25, 30, 31, 33, 34, 35, 0, 1, 2, 3, 4],
[27, 28, 29, 30, 31, 32, 33, 34, 35, 21, 22, 23, 24, 25, 0, 1, 11, 12, 20, 9, 10, 18, 19, 26]]
49 changes: 49 additions & 0 deletions rubiks_cube_gym/envs/skewb_sarah.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from rubiks_cube_gym.envs.skewb import SkewbEnv
import numpy as np
from operator import itemgetter


class SkewbEnvSarah(SkewbEnv):
def __init__(self):
super(SkewbEnvSarah, self).__init__()
self.FL = None

def check_FL(self):
for pos in FL_POS:
if itemgetter(*pos)(self.cube_reduced) == itemgetter(*pos)("WWWWWOOOOOGGGGGRRRRRBBBBBYYYYY"):
return True
return False

def check_solved(self):
if self.cube_reduced == "WWWWWOOOOOGGGGGRRRRRBBBBBYYYYY":
return True

def reward(self):
reward = -40 * self.FL
done = False

if self.check_FL():
reward += 40
self.FL = True
else:
self.FL = False

if self.check_solved():
reward += 60
done = True

if reward <= 0:
reward -= 1

return reward, done

def reset(self, scramble=None):
super(SkewbEnvSarah, self).reset(scramble=scramble)
self.FL = self.check_FL()

return self.cube_state


FL_POS = [[0, 1, 2, 3, 4, 5, 6, 10, 11, 15, 16, 20, 21], [5, 6, 7, 8, 9, 0, 3, 10, 13, 25, 28, 21, 24],
[10, 11, 12, 13, 14, 3, 4, 15, 18, 25, 26, 6, 9], [15, 16, 17, 18, 19, 1, 4, 20, 23, 26, 29, 11, 14],
[20, 21, 22, 23, 24, 16, 19, 28, 29, 5, 8, 0, 1], [25, 26, 27, 28, 29, 8, 9, 13, 14, 18, 19, 23, 24]]
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.2.1',
version='0.3.1',
url="https://github.com/DoubleGremlin181/RubiksCubeGym/",
description="OpenAI Gym environments for various twisty puzzles",
long_description=long_description,
Expand Down

0 comments on commit 8975f0d

Please sign in to comment.