I'm trying to make a cube scramble generator to make moves to scramble my Rubik's cube.
This is my code:
The scramble generator:
switcher.py:
However, when run the code with this:
It returns the moves as:
L
R
L2
Di
Fi
F
R2
Ui
D2
U
U2
Help me to change the code or tell me what is the problem
This is my code:
The scramble generator:
Code:
import random
from switcher import *
class AlgGen3x:
def __init__(self, move_num, move_set):
self.move_num = move_num
self.moves = move_set
self.alg_generator()
# Generate a alg for scramble
def alg_generator(self):
pre_num = ''
for n in range(self.move_num):
print('Creating move ' + str(n))
ran_num = random.randint(1, 18)
if not ran_num == pre_num:
pre_num = ran_num
self.switch(ran_num, self.moves)
self.update()
# Switch for cube 3x
@staticmethod
def switch(tar_obj, tar_set):
global move
while Switcher(tar_obj):
if case(1, 7, 13):
move = 'U'
break
if case(2, 8, 14):
move = 'D'
break
if case(3, 9, 15):
move = 'R'
break
if case(4, 10, 16):
move = 'L'
break
if case(5, 11, 17):
move = 'F'
break
if case(6, 12, 18):
move = 'D'
break
for n in range(7, 13):
if tar_obj == n:
move += 'i'
for n in range(13, 19):
if tar_obj == n:
move += '2'
return tar_set.add(move)
def update(self):
return self.moves
Code:
class Switcher(object):
value = None
def __new__(class_, value):
class_.value = value
return True
def case(*args):
return any((arg == Switcher.value for arg in args))
Code:
# moves = set()
AlgGen3x(25, moves)
for move in moves:
print(move)
L
R
L2
Di
Fi
F
R2
Ui
D2
U
U2
Help me to change the code or tell me what is the problem