This is an attempt a Rubik’s Cube scramble generator. I sometimes get turns of the same face one after the other for example (R,R'). I attempted to fix this using a for and while loop but it didn't work.
import random
def getscramble():
moves = ["R","F","U","L","B","D"]
scramble = []
finascramble = []
for x in range(25):
scramble.append(random.choice(moves))
for x in range(0,len(scramble)-1):
if scramble[x] == scramble[x+1]:
scramble[x] = random.choice(moves)
for x in range(0,len(scramble)-1):
if scramble[x] == "R" and scramble[x+1] == "L":
scramble[x+1] = random.choice(moves)
if scramble[x] == "U" and scramble[x+1]== "D":
scramble[x+1] == random.choice(moves)
if scramble[x] == "F" and scramble[x+1] == "B":
scramble[x+1] == random.choice(moves)
modifiers = ["","2","'"]
for x in range(25):
randy = random.randint(0,2)
finascramble.append(scramble[x]+modifiers[randy])
return " ".join(finascramble)
t = True
while t == True:
again = input()
if again == "s":
print()
print(getscramble())