473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help me with my cube scramble generator

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
0 1158

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

Similar topics

0
by: Creativy, writing and more | last post by:
Hi all, I'm hoping to find some additional help with a site I'm maintaining for my landlord. I'm trying to grow a web hosting and web design business. I was to have this site as a job that would...
2
by: Mekon | last post by:
I have never written a line of script in my life but I need some help with it now. I have this auto generated code which I want to modify if possible The script generates a strip of...
11
by: Duane Lambe | last post by:
Hi folks - site's at http://www.datawire.net/files/intranet.html ; works fine in IE, but open in Firebird/Moz/Opera, and you can see that the word "Home" near the top doesn't move down to line up...
0
by: Michael | last post by:
Hi All, I have a general question. I'm in the process of designing a app that will allow user to enter data for Medical forms and print the corresponding word doc. I have about 100 forms I have to...
5
by: maks | last post by:
Hi! I need some help in modifying this prime number generator code. How do I modify this code so that it assigns prime numbers to an array and returns it? I have tried to get it work but it...
1
by: SilencerXXX | last post by:
Hello All...ok, so here is what I need to do, it's for a computer project I'm working on for school (the teacher said outside help is allowed). What I need to do is similar to a password cracker; I...
0
by: Blubaugh, David A. | last post by:
To All, Has anyone worked with the F2PY generator? This is something that is supposedly built within numpy and scipy for the Python environment. I was wondering if anyone has encountered any...
1
by: Blubaugh, David A. | last post by:
Pauli, Yes, I am utilizing the windows environment. I cannot install f2py. I obtain the following error when I try to execute the setup.py file within the f2py folder located within the...
6
by: HerpsForDerps | last post by:
Hello everyone! I am new to this forum and currently am enrolled in an intro to ECS class where we are working on python programming. This is our last assignment for python and I have been able...
3
by: MattBrady | last post by:
Ok, so I just started learning python and I've made a simple random number generator already but now I want the user to define the range in which the number can be generated. This is what I have so...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.