aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsolver.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/solver.py b/solver.py
index 11ecce0..fbb64a9 100755
--- a/solver.py
+++ b/solver.py
@@ -18,6 +18,7 @@ import copy
import os
import pickle
import time
+import contextlib
import docopt
import yaml
@@ -33,6 +34,7 @@ class Kana:
def __init__(self, type_name, kana=None):
self.type_name = type_name
self.kana = kana
+ self.hash = hash((self.type_name, self.kana))
#print(type_name)
#print(kana)
@@ -64,8 +66,7 @@ class Kana:
return self.type_name == other.type_name and self.kana == other.kana
def __hash__(self):
- #print(f'hash of Kana({self}): {hash((self.type_name, self.kana))}')
- return hash((self.type_name, self.kana))
+ return self.hash
kana_void = Kana.create('void')
@@ -225,8 +226,10 @@ class KanaGrid:
# the bare minimum equal to 1.
self.score, self.myst_count = self.longest_chain()
- def get_grid_hashable(self):
- return tuple(self.grid)
+ def get_key(self):
+ #return tuple(self.grid)
+ #return hash(x for x in self.grid)
+ return hash(tuple(self.grid))
def get_kana(self, pos):
if pos[0] < 0 or pos[0] >= self.width:
@@ -376,6 +379,13 @@ def is_kana_compatible(kana1, kana2):
def generate_possible_grids(kanagrid):
for y in range(kanagrid.height):
for x in range(kanagrid.width):
+ kana_test = kanagrid.get_kana((x, y))
+ if kana_test.type_name not in ('norm', 'froz', 'slim', 'myst',
+ 'ar_u', 'ar_r', 'ar_d', 'ar_l'):
+ continue
+ if kana_test.type_name == 'norm' and not kana_test.kana:
+ continue
+
for action_type in KanaGrid.actions:
new_grid = kanagrid.action((x, y), action_type)
if new_grid:
@@ -389,7 +399,7 @@ def generate_possible_grids(kanagrid):
def generate_all_possible_grids(grid, bests, max_actions):
for pos, action_type, new_grid in generate_possible_grids(grid):
- key = new_grid.get_grid_hashable()
+ key = new_grid.get_key()
if key in bests and bests[key].action_count <= new_grid.action_count:
continue
bests[key] = new_grid