diff --git a/src/statebag.py b/src/statebag.py --- a/src/statebag.py +++ b/src/statebag.py @@ -31,6 +31,40 @@ def estimateDistance(diff): return replacements+1 # ??? +## Update contents of diff1 by contents of diff2. +def updateDiff(diff1,diff2): + res=[] + i=j=0 + m=len(diff1) + n=len(diff2) + while i3: return # we couldn't find every such move sequence anyway without a clever algorithm weightEst=s.getWeight()+2-distEst @@ -114,11 +148,13 @@ class StateBag: sn=BoardState(board) if len(self._states)>0: if sn==self._states[-1]: return None # no change - sn.diff2Prev=sn-self._states[-1] + sn.cachedDiff=sn-self._states[-1] else: sn.setWeight(1) + diff=sn.cachedDiff for s in reversed(self._states): - sn.tryConnect(s) + sn.tryConnect(s,diff) + diff=updateDiff(s.cachedDiff,diff) self._states.append(sn) return sn