-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scrambler.py
89 lines (67 loc) · 2.11 KB
/
Scrambler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from numpy import random
import Cube
def alg(n):
move = [["R","L"], ["U","D"], ["F","B"]]
direction = [" ","'","2"]
algorithm = ""
algor_list = []
parallel = False
prevMove = "A"
prevY = 0
i = 0
while i < n:
x = random.randint(2)
y = random.randint(3)
newMove = move[y][x]
if newMove == prevMove:
pass
elif newMove in move[prevY]:
if not parallel:
algor_list.append(newMove + direction[random.randint(3)])
algorithm += algor_list[-1] + " "
prevMove = newMove
prevY = y
parallel = True
i += 1
else:
algor_list.append(newMove + direction[random.randint(3)])
algorithm += algor_list[-1] + " "
prevMove = newMove
prevY = y
parallel = False
i += 1
print algorithm + "\n"
return algor_list
def scrambler(n):
algor_list = alg(n)
cube = Cube.Cube()
for x in algor_list:
if x[1] == " ":
repeat = 1
elif x[1] == "2":
repeat = 2
elif x[1] == "'":
repeat = 3
for i in range(repeat):
if x[0] == "R":
cube.r()
elif x[0] == "L":
cube.l()
elif x[0] == "U":
cube.u()
elif x[0] == "D":
cube.d()
elif x[0] == "F":
cube.f()
else:
cube.b()
print cube
def main():
print "Rubik's Cube scrambler by Ching, input the length of random algorithm you want and the resulting cube will be shown\nThis scrambler assume the use of Western color sheme with white face to the top and blue to the player"
cube2 = Cube.Cube()
print "Basic orientation:"
print cube2
moves = input("Please input the number of steps you want the crambler to have: ")
print "For the meaning of algorithm, please refer to: \nhttp://w.astro.berkeley.edu/~converse/rubiks.php?id1=basics&id2=notation"
scrambler(moves)
main()