mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Extract a method.
This commit is contained in:
parent
788965a55a
commit
7d091f42ab
1 changed files with 9 additions and 11 deletions
|
@ -850,16 +850,18 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
def put_str(target, str_):
|
def put_str(target, str_):
|
||||||
put(target, SUITS_S.index(str_[1]), RANKS_S.index(str_[0]))
|
put(target, SUITS_S.index(str_[1]), RANKS_S.index(str_[0]))
|
||||||
|
|
||||||
|
def my_find_re(RE, m):
|
||||||
|
s = m.group(1)
|
||||||
|
assert re.match(r'^\s*(?:' + RE + r')?(?:\s+'
|
||||||
|
+ RE + r')*\s*$', s)
|
||||||
|
return re.findall(r'\b' + RE + r'\b', s)
|
||||||
|
|
||||||
for line_p in fh:
|
for line_p in fh:
|
||||||
line = line_p.rstrip('\r\n')
|
line = line_p.rstrip('\r\n')
|
||||||
m = re.match(r'^(?:Foundations:|Founds?:)\s*(.*)', line)
|
m = re.match(r'^(?:Foundations:|Founds?:)\s*(.*)', line)
|
||||||
if m:
|
if m:
|
||||||
RE = r'(' + SUITS_RE + r')-([' + RANKS0_S + r'])'
|
for gm in my_find_re(
|
||||||
s = m.group(1)
|
r'(' + SUITS_RE + r')-([' + RANKS0_S + r'])', m):
|
||||||
assert re.match(r'^\s*(?:' + RE + r')?(?:\s+'
|
|
||||||
+ RE + r')*\s*$', s)
|
|
||||||
g = re.findall(r'\b' + RE + r'\b', s)
|
|
||||||
for gm in g:
|
|
||||||
for foundat in game.foundations:
|
for foundat in game.foundations:
|
||||||
suit = foundat.cap.suit
|
suit = foundat.cap.suit
|
||||||
if SUITS_S[suit] == gm[0]:
|
if SUITS_S[suit] == gm[0]:
|
||||||
|
@ -869,11 +871,7 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
continue
|
continue
|
||||||
m = re.match(r'^(?:FC:|Freecells:)\s*(.*)', line)
|
m = re.match(r'^(?:FC:|Freecells:)\s*(.*)', line)
|
||||||
if m:
|
if m:
|
||||||
RE = r'(' + CARD_RE + r'|\-)'
|
g = my_find_re(r'(' + CARD_RE + r'|\-)', m)
|
||||||
s = m.group(1)
|
|
||||||
assert re.match(r'^\s*(?:' + RE + r')?(?:\s+'
|
|
||||||
+ RE + r')*\s*$', s)
|
|
||||||
g = re.findall(r'\b' + RE + r'\b', s)
|
|
||||||
while len(g) < len(game.reserves):
|
while len(g) < len(game.reserves):
|
||||||
g.append('-')
|
g.append('-')
|
||||||
for i, gm in enumerate(g):
|
for i, gm in enumerate(g):
|
||||||
|
|
Loading…
Add table
Reference in a new issue