diff options
author | vg <vgm+dev@devys.org> | 2020-05-21 01:20:13 +0200 |
---|---|---|
committer | vg <vgm+dev@devys.org> | 2020-05-21 01:20:13 +0200 |
commit | 9c4c2b5468c9136181c3c9c95f441de0a1d08fe0 (patch) | |
tree | 384440ab5d9310c44484b938eff5287997e8c894 | |
parent | bc706018b92df380052fe0ab76af533bc8225fa8 (diff) | |
download | kana_quest_solver-9c4c2b5468c9136181c3c9c95f441de0a1d08fe0.tar.gz kana_quest_solver-9c4c2b5468c9136181c3c9c95f441de0a1d08fe0.tar.bz2 kana_quest_solver-9c4c2b5468c9136181c3c9c95f441de0a1d08fe0.zip |
speedupwip2
-rwxr-xr-x | solver.py | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -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 |