aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarianne Chevrot <blackmoor+git@devys.org>2020-05-17 11:22:23 +0200
committerMarianne Chevrot <blackmoor+git@devys.org>2020-05-17 11:22:23 +0200
commitade4ec6a8393c5173f1d6202131f4888384c861c (patch)
tree76a393b3557816b109ba710d1586971418c4fcc4
parente019b29657a69c19121c6a145d065b7e23baf093 (diff)
downloadkana_quest_solver-ade4ec6a8393c5173f1d6202131f4888384c861c.tar.gz
kana_quest_solver-ade4ec6a8393c5173f1d6202131f4888384c861c.tar.bz2
kana_quest_solver-ade4ec6a8393c5173f1d6202131f4888384c861c.zip
separate solution generation and its display
-rw-r--r--.coverage2
-rwxr-xr-xsolver.py16
-rw-r--r--tests_solver/test_solver.py11
3 files changed, 12 insertions, 17 deletions
diff --git a/.coverage b/.coverage
index f5776d2..6686567 100644
--- a/.coverage
+++ b/.coverage
@@ -1 +1 @@
-!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/storage/Games/kana_quest/kana_quest_solver/solver.py":[5,17,18,20,21,23,25,27,29,45,48,51,30,31,35,38,54,56,58,69,79,108,143,150,173,192,195,204,212,219,246,255,258,265,274,308,312,320,329,339,347,357,388,39,42,43,61,62,63,64,65,66,67,46,80,205,207,210,81,83,84,85,86,87,88,82,90,91,93,94,95,96,92,98,99,100,105,106,109,110,111,112,70,71,72,73,74,75,76,113,114,213,215,217,115,267,268,269,49,270,266,40,116,118,119,120,121,117,123,124,125,126,127,128,129,130,131,132,134,135,136,137,138,139,140,220,222,228,229,230,231,233,236,237,239,242,243,244,141,259,193,174,175,176,177,178,144,145,146,147,148,179,181,182,151,152,154,155,156,157,159,160,161,162,158,164,165,167,208,168,171,183,184,185,186,187,188,169,313,315,317,206,316,170,166,180,189,261,262,276,277,278,279,280,281,282,283,284,275,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,304,305,260,309,101,102,103,240,104]}} \ No newline at end of file
+!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/storage/Games/kana_quest/kana_quest_solver/solver.py":[5,17,18,20,21,23,25,27,29,45,48,51,30,31,35,38,54,56,58,69,79,108,143,150,173,192,195,204,212,219,246,255,258,265,274,308,312,320,329,339,347,357,366,391,39,42,43,61,62,63,64,65,66,67,46,80,205,207,210,81,83,84,85,86,87,88,82,90,91,93,94,95,96,92,98,99,100,105,106,109,110,111,112,70,71,72,73,74,75,76,113,114,213,215,217,115,267,268,269,49,270,266,40,116,118,119,120,121,117,123,124,125,126,127,128,129,130,131,132,134,135,136,137,138,139,140,220,222,228,229,230,231,233,236,237,239,242,243,244,141,259,193,174,175,176,177,178,144,145,146,147,148,179,181,182,151,152,154,155,156,157,159,160,161,162,158,164,165,167,208,168,171,183,184,185,186,187,188,169,313,315,317,206,316,170,166,180,189,261,262,276,277,278,279,280,281,282,283,284,275,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,304,305,260,309,101,102,103,240,104,247,248,249,252,250,253,358,359,330,321,322,323,324,325,326,331,196,197,198,199,200,202,332,334,335,336,223,224,225,226,333,360,361,362,363]}} \ No newline at end of file
diff --git a/solver.py b/solver.py
index b42cbc4..d10d347 100755
--- a/solver.py
+++ b/solver.py
@@ -354,18 +354,13 @@ def print_score_over(node, target_score):
print_score_over(child, target_score)
-def search_all_solution(args, kanagrid, target_score, max_actions):
+def search_all_solution(kanagrid, target_score, max_actions):
grids = {}
generate_all_possible_grids(kanagrid, grids=grids, max_actions=max_actions)
for grid in grids.values():
grid.update_score()
if grid.score >= target_score and grid.myst_count == 0:
- print("="*80)
- if args['-p']:
- print(repr_grid_with_parents(grid))
- else:
- print(grid)
- return grid
+ yield grid
def main():
@@ -385,7 +380,12 @@ def main():
if args['--print']:
return
- search_all_solution(args, kanagrid, target_score, max_actions)
+ for grid in search_all_solution(kanagrid, target_score, max_actions):
+ print("="*80)
+ if args['-p']:
+ print(repr_grid_with_parents(grid))
+ else:
+ print(grid)
if __name__ == '__main__':
diff --git a/tests_solver/test_solver.py b/tests_solver/test_solver.py
index 1d441ff..808804e 100644
--- a/tests_solver/test_solver.py
+++ b/tests_solver/test_solver.py
@@ -216,15 +216,10 @@ def test_solver_load_and_type_1():
target_score = input_dict['target_score']
max_actions = input_dict['max_actions']
- mock_args = {'--help': False,
- '--print': False,
- '-p': False,
- 'YAML_GRID': type_yaml_level_file,
- }
-
assert loaded_grid == kanagrid_orig
- kanagrid_new = search_all_solution(mock_args, loaded_grid, target_score, max_actions)
+ grids = list(search_all_solution(loaded_grid, target_score, max_actions))
- assert kanagrid_new == expected_grid
+ assert len(grids) == 1
+ assert grids[0] == expected_grid