diff options
| author | Charlie Blake | 2018-02-23 11:51:06 +0000 |
|---|---|---|
| committer | GitHub | 2018-02-23 11:51:06 +0000 |
| commit | dd731b92b0a8f984ddbef11d31bc70acfa266510 (patch) | |
| tree | 071d463dc62ec584ef275759f7dbc450027a99d7 /optimisation-test.py | |
| parent | Merge pull request #39 from thecharlesblake/update-objectives (diff) | |
| parent | Enable suit reduction for non-foundation games (diff) | |
| download | metasol-dd731b92b0a8f984ddbef11d31bc70acfa266510.tar.gz metasol-dd731b92b0a8f984ddbef11d31bc70acfa266510.zip | |
Merge pull request #40 from thecharlesblake/test-optimisations
Test optimisations
Diffstat (limited to 'optimisation-test.py')
| -rw-r--r-- | optimisation-test.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/optimisation-test.py b/optimisation-test.py new file mode 100644 index 0000000..6f936ef --- /dev/null +++ b/optimisation-test.py @@ -0,0 +1,71 @@ +import sys +from subprocess import run, CalledProcessError, DEVNULL, PIPE, Popen + +runCount = 7500 + +# Loops through each canonical solitaire + +for optimisation in ["-no-reduced-state", + "-no-pile-symmetry", + "-no-auto-foundations"]: + for preset in [ + "simple-alpha-star", + "simple-bakers-dozen", + "simple-black-hole", + "simple-canfield", + "simple-flower-garden", + "simple-fortunes-favor", + "simple-free-cell", + "simple-somerset", + "simple-spanish-patience", + "simple-spider"]: + + differs = [] + + for attempt in range(runCount): + try: + op_p = Popen("./cmake-build-release/bin/solvitaire" + optimisation + + " --type " + preset + " --random " + str(attempt) + + " --classify", + shell=True, + stdout=PIPE, + stderr=DEVNULL) + out_str = op_p.stdout.readline() + if out_str == b'Solved\n': + op_res = True + elif out_str == b'No solution\n': + op_res = False + else: + raise Exception('Invalid return value!') + + no_op_p = Popen("./cmake-build-release/bin/solvitaire" + + " --type " + preset + " --random " + str(attempt) + + " --classify", + shell=True, + stdout=PIPE, + stderr=DEVNULL) + out_str = no_op_p.stdout.readline() + if out_str == b'Solved\n': + no_op_res = True + elif out_str == b'No solution\n': + no_op_res = False + else: + raise Exception('Invalid return value!') + + if op_res != no_op_res: + differs.append(attempt) + + except CalledProcessError: + print("Error running " + preset + " with seed " + str(attempt) + "!") + sys.exit() + except: + print("Unknown error in script") + sys.exit() + + run("pkill solvitaire", shell=True) + + if not differs : + print(preset + ": No difference in solutions for " + optimisation) + else : + print(preset + ": Optimisation " + optimisation + " differs for the following seeds:") + print(differs) |
