By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,953 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,953 IT Pros & Developers. It's quick & easy.

Help me with my cube scramble generator

P: 1
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:
Expand|Select|Wrap|Line Numbers
  1. import random
  2. from switcher import *
  3.  
  4.  
  5. class AlgGen3x:
  6.     def __init__(self, move_num, move_set):
  7.         self.move_num = move_num
  8.         self.moves = move_set
  9.         self.alg_generator()
  10.  
  11.     # Generate a alg for scramble
  12.     def alg_generator(self):
  13.         pre_num = ''
  14.         for n in range(self.move_num):
  15.             print('Creating move ' + str(n))
  16.             ran_num = random.randint(1, 18)
  17.             if not ran_num == pre_num:
  18.                 pre_num = ran_num
  19.                 self.switch(ran_num, self.moves)
  20.         self.update()
  21.  
  22.     # Switch for cube 3x
  23.     @staticmethod
  24.     def switch(tar_obj, tar_set):
  25.         global move
  26.         while Switcher(tar_obj):
  27.             if case(1, 7, 13):
  28.                 move = 'U'
  29.                 break
  30.             if case(2, 8, 14):
  31.                 move = 'D'
  32.                 break
  33.             if case(3, 9, 15):
  34.                 move = 'R'
  35.                 break
  36.             if case(4, 10, 16):
  37.                 move = 'L'
  38.                 break
  39.             if case(5, 11, 17):
  40.                 move = 'F'
  41.                 break
  42.             if case(6, 12, 18):
  43.                 move = 'D'
  44.                 break
  45.  
  46.         for n in range(7, 13):
  47.             if tar_obj == n:
  48.                 move += 'i'
  49.  
  50.         for n in range(13, 19):
  51.             if tar_obj == n:
  52.                 move += '2'
  53.  
  54.         return tar_set.add(move)
  55.  
  56.     def update(self):
  57.         return self.moves
  58.  
switcher.py:
Expand|Select|Wrap|Line Numbers
  1. class Switcher(object):
  2.  
  3.     value = None
  4.  
  5.     def __new__(class_, value):
  6.         class_.value = value
  7.         return True
  8.  
  9.  
  10. def case(*args):
  11.     return any((arg == Switcher.value for arg in args))
  12.  
However, when run the code with this:
Expand|Select|Wrap|Line Numbers
  1. # moves = set()
  2.  
  3. AlgGen3x(25, moves)
  4. for move in moves:
  5.     print(move)
  6.  
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
May 1 '16 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.