I want to randomize a rubik's cube that is initialized as complete (all colors on the correct sides). I have move functions that rotate the cube. I want to randomly pick 50 functions in a row to properly randomize it.
I am doing this project to learn a little bit more about Python, since I mostly do C++ and I see there is no case/switch for Python, so I am trying a dictionary. When I make the dictionary, the code seems to execute for some reason:
def random_cube(self):
scramble = { 0 : self.up_turn(),
1 : self.down_turn(),
2 : self.left_turn(),
3 : self.right_turn(),
4 : self.front_turn(),
5 : self.back_turn(),
6 : self.up_turn("inverted"),
7 : self.down_turn("inverted"),
8 : self.left_turn("inverted"),
9 : self.right_turn("inverted"),
10: self.front_turn("inverted"),
11: self.back_turn("inverted")
}
for x in range(50):
i = random.randint(0,11)
scramble[i]
So when I make this dictionary, it seems to run through and execute all 11 entries for some reason (I think). I can't seem to find a better way, at least more elegant than a long if/elif string of statements.
!EDIT: Implementing both suggestions, the ("inverted") flag for the functions are not being set by either suggestion. For example, calling 1 and 7 both give me down_turn, but the output shows that the flag was not set when it should have been on number 7.
Any ideas?