diff options
Diffstat (limited to 'python/examples')
| -rw-r--r-- | python/examples/pause_resume.py | 35 | ||||
| -rw-r--r-- | python/examples/solve.py | 6 |
2 files changed, 37 insertions, 4 deletions
diff --git a/python/examples/pause_resume.py b/python/examples/pause_resume.py new file mode 100644 index 0000000..5daebeb --- /dev/null +++ b/python/examples/pause_resume.py | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | # This example is meant to test the pause / resume / stop mechanism | ||
| 2 | # See the solve.py example for more details on how this works | ||
| 3 | |||
| 4 | import sys, os, time | ||
| 5 | |||
| 6 | sys.path.append(os.getcwd()) | ||
| 7 | sys.path.append(os.getcwd() + os.path.sep + "python") | ||
| 8 | import nissy | ||
| 9 | |||
| 10 | # Function used to pause, resume and kill the solver | ||
| 11 | t0 = time.time() | ||
| 12 | def poll(): | ||
| 13 | t = time.time() - t0 | ||
| 14 | if t < 3: | ||
| 15 | print("[{}s] pausing for the first 3 seconds".format(t)) | ||
| 16 | return nissy.status_pause | ||
| 17 | if t < 6: | ||
| 18 | print("[{}s] Letting the solver run for 3 seconds".format(t)) | ||
| 19 | return nissy.status_run | ||
| 20 | print("[{}s] Too much time has passed, giving up".format(t)) | ||
| 21 | return nissy.status_stop | ||
| 22 | |||
| 23 | solver = "h48h0k4" | ||
| 24 | datapath = "tables" + os.path.sep + solver | ||
| 25 | if os.path.exists(datapath): | ||
| 26 | data = bytearray(open(datapath, "rb").read()) | ||
| 27 | else: | ||
| 28 | data = nissy.gendata("h48h0k4") | ||
| 29 | print("Generated data will NOT be persisted") | ||
| 30 | |||
| 31 | # Scramble is 19 moves optimal, should take a while with the h48h0k4 solver | ||
| 32 | scramble = "R' U' F D R F2 D L F D2 F2 L' U R' L2 D' R2 F2 R2 D L2 U2 R' U' F" | ||
| 33 | cube = nissy.applymoves(nissy.solved_cube, scramble); | ||
| 34 | |||
| 35 | nissy.solve(cube, solver, nissy.nissflag_normal, 0, 9, 3, 20, 4, data, poll) | ||
diff --git a/python/examples/solve.py b/python/examples/solve.py index 75e7914..c2c992b 100644 --- a/python/examples/solve.py +++ b/python/examples/solve.py | |||
| @@ -3,12 +3,10 @@ | |||
| 3 | # Run "./build.sh python", then run this from either the top-level directory | 3 | # Run "./build.sh python", then run this from either the top-level directory |
| 4 | # of the nissy-core repo or from the python subdirectory. | 4 | # of the nissy-core repo or from the python subdirectory. |
| 5 | 5 | ||
| 6 | # Append the directories to the python path so we can load the module | 6 | # Append the directories to the python path and import |
| 7 | import sys, os | 7 | import sys, os |
| 8 | sys.path.append(os.getcwd()) | 8 | sys.path.append(os.getcwd()) |
| 9 | sys.path.append(os.getcwd() + os.path.sep + "python") | 9 | sys.path.append(os.getcwd() + os.path.sep + "python") |
| 10 | |||
| 11 | # Import with a nicer name | ||
| 12 | import nissy | 10 | import nissy |
| 13 | 11 | ||
| 14 | # Choose the solver you prefer | 12 | # Choose the solver you prefer |
| @@ -26,7 +24,7 @@ else: | |||
| 26 | cube = nissy.applymoves(nissy.solved_cube, "U F R2"); | 24 | cube = nissy.applymoves(nissy.solved_cube, "U F R2"); |
| 27 | 25 | ||
| 28 | # Solve! | 26 | # Solve! |
| 29 | solutions = nissy.solve(cube, solver, nissy.nissflag_normal, 0, 9, 3, 20, 4, data) | 27 | solutions = nissy.solve(cube, solver, nissy.nissflag_normal, 0, 9, 3, 20, 4, data, None) |
| 30 | 28 | ||
| 31 | # Print the solutions, one per line | 29 | # Print the solutions, one per line |
| 32 | print("Found ", len(solutions), " solutions:") | 30 | print("Found ", len(solutions), " solutions:") |
