1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-15 02:54:09 -04:00

Convert to regex.

This commit is contained in:
Shlomi Fish 2013-04-15 18:40:25 +03:00
parent fbd5106fdc
commit 3b921faa61

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env pytho
# -*- mode: python; coding: utf-8; -*- # -*- mode: python; coding: utf-8; -*-
##---------------------------------------------------------------------------## ##---------------------------------------------------------------------------##
## ##
@ -771,6 +771,15 @@ class FreeCellSolver_Hint:
#print hint #print hint
return [hint] return [hint]
def colonPrefixMatch(self, prefix, s):
m = re.match(prefix + ': (\d+)', s)
if m:
self._v = int(m.group(1))
return True
else:
self._v = None
return False
def computeHints(self): def computeHints(self):
game = self.game game = self.game
game_type = self.game_type game_type = self.game_type
@ -862,23 +871,21 @@ class FreeCellSolver_Hint:
iter = 0 iter = 0
depth = 0 depth = 0
states = 0 states = 0
for s in pout: for s in pout:
if DEBUG >= 5: if DEBUG >= 5:
print s, print s,
if s.startswith('Iter'):
#print `s` if self.colonPrefixMatch('Iteration', s):
iter = int(s[10:-1]) iter = self._v
elif s.startswith('Depth'): elif self.colonPrefixMatch('Depth', s):
#print s, depth = self._v
depth = int(s[6:-1]) elif self.colonPrefixMatch('Stored-States', s):
elif s.startswith('Stor'): states = self._v
#print s,
states = int(s[14:-1])
if iter % 100 == 0: if iter % 100 == 0:
self.dialog.setText(iter=iter, depth=depth, self.dialog.setText(iter=iter, depth=depth,
states=states) states=states)
elif s.startswith('-=-') or \ elif re.search('^(?:-=-=|I could not solve this game)', s):
s.startswith('I co'): # "I could not solve this game."
break break
self.dialog.setText(iter=iter, depth=depth, states=states) self.dialog.setText(iter=iter, depth=depth, states=states)