diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-14 14:00:44 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-14 14:00:44 +0200 |
| commit | 3ab1012ea8c55f82812b5998fd6b4fdf53dea70e (patch) | |
| tree | d18552619a364fcb816d5e2d2331822edd7e2045 /python/examples | |
| parent | 7b8c1e4634784b57bb6223cd780d5c67f5381d43 (diff) | |
| download | nissy-core-3ab1012ea8c55f82812b5998fd6b4fdf53dea70e.tar.gz nissy-core-3ab1012ea8c55f82812b5998fd6b4fdf53dea70e.zip | |
Improved C++ API and added info to README
Diffstat (limited to 'python/examples')
| -rw-r--r-- | python/examples/solve.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/python/examples/solve.py b/python/examples/solve.py new file mode 100644 index 0000000..b939183 --- /dev/null +++ b/python/examples/solve.py | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | # Small example of nissy_python_module usage | ||
| 2 | |||
| 3 | # Compile the python module with "make python", then run this from the main | ||
| 4 | # folder containing nissy_python_module.so | ||
| 5 | |||
| 6 | # Append the main folder to the python path so we can load the module | ||
| 7 | from sys import path | ||
| 8 | path.append("./") | ||
| 9 | |||
| 10 | # Import with a nicer name | ||
| 11 | import nissy_python_module as nissy | ||
| 12 | |||
| 13 | # Choose the solver you prefer | ||
| 14 | solver = "h48h0k4" | ||
| 15 | |||
| 16 | # Load the pruning table from file | ||
| 17 | data = bytearray(open("tables/" + solver, "rb").read()) | ||
| 18 | |||
| 19 | # If you have not generated the table yet, you can do so: | ||
| 20 | # data = nissy.gendata("h48h0k4") | ||
| 21 | |||
| 22 | # Get a scrambled cube | ||
| 23 | cube = nissy.applymoves(nissy.solved_cube, "U F R2"); | ||
| 24 | |||
| 25 | # Solve! | ||
| 26 | solutions = nissy.solve(cube, solver, nissy.nissflag_normal, 0, 9, 3, -1, 4, data) | ||
| 27 | |||
| 28 | # Print the solutions, one per line | ||
| 29 | print("Found ", len(solutions), " solutions:") | ||
| 30 | for s in solutions: | ||
| 31 | print(s) | ||
| 32 | |||
| 33 | # You can use help(nissy) for more info about the available methods: | ||
| 34 | # help(nissy) | ||
| 35 | |||
| 36 | # Or help(nissy.methodname) if you want to know more about a specific method: | ||
| 37 | # help(nissy.solve) | ||
