-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
334 lines (286 loc) · 12 KB
/
main.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
"""
Rubix Cube Solver - Main Script
v0.12 (alpha)
History available at github.com/OliverMatthews/rubiksCube/
Oli Matthews 2019
"""
# Imports relevant libraries.
import dev
import user
# This function serves as the main menu for the program. It gives the user a
# list of options for what they would like to do with the program. Takes no
# inputs, and returns a boolean.
def mainMenu():
# Prints a list of options for the user.
print("\n" + "*** RUBIK'S CUBE SOLVER - MAIN MENU ***")
print("Please choose from the following options:")
print("1 - Solve a specific cube.")
print("2 - (DEVELOPER) Run simulations.")
print("3 - (DEVELOPER) Change developer settings.")
print("0 - Exit.")
# Asks for the user's selection.
userInput = int(input(""))
# If user opts to solve a specific cube.
if userInput == 1:
# Repeats the menu option repeatedly until the user selects to return
# to the main menu.
menuBool = True
while menuBool == True:
menuBool = option1()
# Returns true, to loop back to the main menu again.
return True
# If user opts to run simulations.
elif userInput == 2:
# Repeats the menu option repeatedly until the user selects to return
# to the main menu.
menuBool = True
while menuBool == True:
menuBool = option2()
# Returns true, to loop back to the main menu again.
return True
# If user opts to change settings.
elif userInput == 3:
# Repeats the menu option repeated until the user selects to return
# to the main menu.
menuBool = True
while menuBool == True:
menuBool = option3()
# Returns true, to loop back to the main menu again.
return True
# If user opts to exit the program.
elif userInput == 0:
print("See you soon! :)")
# Returns false, to exit the loop and end the program.
return False
# If the user makes an invalid selection.
else:
print("That selection was not recognised.")
# Returns true, to loop back to the main menu again.
return True
# Asks the user for the state of their cube, then solves it, and prints out
# a list of instructions for the user to follow.
def option1():
# Initialises a new instance of the rubiks cube class, size 3.
gamecube = user.solve.cube.rubikCube(3)
# Gets the state of the cube from the user.
user.getCube(gamecube)
# Prints out instructions for the user to follow.
user.instructions(gamecube)
# Loop to ask the user if they would like to solve another cube or return
# to the main menu.
while True:
print("Would you like to solve another cube?")
print("1 - Solve another cube")
print("0 - Return to main menu")
userInput = int(input(""))
# If the user opts to return to the main menu.
if userInput == 0:
# Returns false to break the main menu loop.
return False
break
# If the user opts to solve another cube.
elif userInput == 1:
# Returns true to maintain the main menu loop.
return True
break
# If the user makes an invalid selection.
else:
print("That selection was not recognised.")
continue
# This function is run if the user opts to run simulations. It asks the user
# how many simulations they would like to run (and checks that it is a sensible
# number), then runs them.
def option2():
# Asks the user how many simulations they would like to run.
numberOfSimulations = int(input("How many simulations would you like to run? "))
# Checks the number of simulations to see how large the number is. This
# check exists to ensure the user does not accidentally input a very large
# number which will take an exceptionally long time to complete.
if numberOfSimulations <= 10000:
# Runs the simulations without checking if the number of simulation is
# less than 10 000.
dev.runManySimulations(numberOfSimulations)
elif numberOfSimulations > 10000:
# Queries the user if they meant to input such a large number of
# simulations. User is required to input the same number in again, to
# confirm,
print("WARNING: Running this many simulations may take a significant amount of time. Please enter the same number of simulations again to confirm.")
confirmationNumberOfSimulations = int(input("Confirm number of simulations: "))
# Checks the confirmation number against the original number of
# simulations.
if confirmationNumberOfSimulations == numberOfSimulations:
# If the numbers match, runs the desired number of simulations.
dev.runManySimulations(numberOfSimulations)
else:
# If the numbers do not match, cancels running the simulations.
print("Inputs did not match - running simulations cancelled.")
# Loops the following submenu until a valid selection is made.
while True:
# Prints a list of options for the user.
print("Would you like to run more simulations?")
print("1 - Run more simulations")
print("0 - Return to main menu")
userInput = int(input(""))
# If the user opts to return to the main menu.
if userInput == 0:
return False
break
# If the user opts to run more simulations.
elif userInput == 1:
return True
break
# If the user makes an invalid selection.
else:
print("That selection was not recognised.")
continue
# This function is run if the user opts to change the developer settings.
# A sub-menu is provided to ask the user which setting(s) they wish to alter.
def option3():
# Prints a list of options for the user.
print("Please select a developer setting to change from the list below:")
print("1 - Sequence Printing")
print("2 - Simulation pass/fail statistics printing")
print("3 - Simulation final time statistics printing")
print("4 - Solution Saving")
userInput = int(input(""))
# Runs whichever selection the user makes.
if userInput == 1:
option3_1()
elif userInput == 2:
option3_2()
elif userInput == 3:
option3_4()
elif userInput == 4:
option3_5()
# If the user makes an invalid selection, prints that the selection was
# not recognised.
else:
print("That selection was not recognised.")
# Loops the following submenu until a valid selection is made.
while True:
print("Would you like to change other settings?")
print("1 - Change more settings")
print("0 - Return to main menu")
userInput = int(input(""))
# Runs whichever selection the user makes.
if userInput == 0:
return False
break
elif userInput == 1:
return True
break
# If the user makes an invalid selection, prints that the selection
# was not recognised.
else:
print("That selection was not recognised.")
continue
# This function is run if the user opts to change the state of the sequence
# printing setting. A sub-menu is provided to ask the user whether they
# wish to enable or disable sequence printing.
def option3_1():
# Prints a list of options for the user.
print("Please choose whether to enable or disable Sequence Printing.")
print("1 - Enable (turn ON sequence printing)")
print("2 - Disable (turn OFF sequence printing)")
userInput = int(input(""))
# Runs whichever selection the user makes.
if userInput == 1:
option3_1_1()
elif userInput == 2:
option3_1_2()
# If the user makes an invalid selection, prints that the selection was
# not recognised.
else:
print("That selection was not recognised.")
# This function is run if the user opts to enable sequence printing.
def option3_1_1():
dev.devSettings.toggleSequencePrinting(True)
# This function is run if the user opts to disable sequence printing.
def option3_1_2():
dev.devSettings.toggleSequencePrinting(False)
# This function is run if the user opts to change the state of the simulation
# pass/fail statistics printing setting. A sub-menu is provided to ask the user
# whether they wish to enable or disable simulation pass/fail statistics
# printing.
def option3_2():
# Prints a list of options for the user.
print("Please choose whether to enable or disable simulation pass/fail statistics printing")
print("1 - Enable (turn ON simulation pass/fail statistics printing)")
print("2 - Disable (turn OFF simulation pass/fail statistics printing)")
userInput = int(input(""))
# Runs whichever selection the user makes.
if userInput == 1:
option3_2_1()
elif userInput == 2:
option3_2_2()
# If the user makes an invalid selection, prints that the selection was
# not recognised.
else:
print("That selection was not recognised.")
# This function is run if the user opts to enable simulation pass/fail
# statistics printing.
def option3_2_1():
dev.devSettings.toggleSimFailStatsPrinting(True)
# This function is run if the user opts to disable simulation pass/fail
# statistics printing.
def option3_2_2():
dev.devSettings.toggleSimFailStatsPrinting(False)
# This function is run if the user opts to change the state of the simulation
# final time statistics printing setting. A sub-menu is provided to ask the
# user whether they wish to enable or disable the simulation final time
# statistics printing setting.
def option3_4():
# Prints a list of options for the user.
print("Please choose whether to enable or disable simulation final time statistics printing")
print("1 - Enable (turn ON simulation final time statistics printing)")
print("2 - Disable (turn OFF simulation final time statistics printing)")
userInput = int(input(""))
# Runs whichever selection the user makes.
if userInput == 1:
option3_4_1()
elif userInput == 2:
option3_4_2()
# If the user makes an invalid selection, prints that the selection was not
# recognised.
else:
print("That selection was not recognised.")
# This function is run if the user opts to enable simulation final time
# statistics printing.
def option3_4_1():
dev.devSettings.toggleFinalTimeStatsPrinting(True)
# This function is run if the user opts to disable simulation final time
# statistics printing.
def option3_4_2():
dev.devSettings.toggleFinalTimeStatsPrinting(False)
# This function is run if the user opts to change the state of the solution
# saving setting. A sub-menu is provided to ask the user whether they wish to
# enable or disable the solution saving setting.
def option3_5():
# Prints a list of options for the user.
print("Please choose whether to enable or disable solution saving")
print("1 - Enable (turn ON solution saving)")
print("2 - Disable (turn OFF solution saving)")
userInput = int(input(""))
# Runs whichever selection the user makes.
if userInput == 1:
option3_5_1()
elif userInput == 2:
option3_5_2()
# If the user makes an invalid selection, prints that the selection was not
# recognised.
else:
print("That selection was not recognised.")
# This function is run if the user opts to enable the saving solutions setting.
def option3_5_1():
dev.devSettings.toggleSaveSolutions(True)
# This function is run if the user opts to disable the saving solutions
# setting.
def option3_5_2():
dev.devSettings.toggleSaveSolutions(False)
# Loops running the main menu until the user opts to exit the program.
menuBool = True
while menuBool == True:
# Runs the main menu function. All options in the main menu return true
# to continue running the loop, with the exception of the option to exit,
# which returns false and ends execution of the program.
menuBool = mainMenu()