mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Extract some common exprs.
This commit is contained in:
parent
e477f4bcf1
commit
d500c84f85
1 changed files with 10 additions and 5 deletions
|
@ -824,6 +824,10 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
game = s_game.s
|
game = s_game.s
|
||||||
stack_idx = 0
|
stack_idx = 0
|
||||||
|
|
||||||
|
RANKS_S = "A23456789TJQK"
|
||||||
|
RANKS_RE = '[' + RANKS_S + ']'
|
||||||
|
CARD_RE = RANKS_RE + '[CSHD]'
|
||||||
|
|
||||||
def cards():
|
def cards():
|
||||||
return game.talon.cards
|
return game.talon.cards
|
||||||
|
|
||||||
|
@ -838,25 +842,26 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
s_game.moveMove(1, game.talon, target, frames=0)
|
s_game.moveMove(1, game.talon, target, frames=0)
|
||||||
|
|
||||||
def put_str(target, str_):
|
def put_str(target, str_):
|
||||||
put(target, "CSHD".index(str_[1]), "A23456789TJQK".index(str_[0]))
|
put(target, "CSHD".index(str_[1]), RANKS_S.index(str_[0]))
|
||||||
|
|
||||||
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:
|
||||||
g = re.findall(r'\b([HCDS])-([0A23456789TJQK])\b', m.group(1))
|
g = re.findall(r'\b([HCDS])-([0' + RANKS_S + r'])\b',
|
||||||
|
m.group(1))
|
||||||
for gm in g:
|
for gm in g:
|
||||||
for foundat in game.foundations:
|
for foundat in game.foundations:
|
||||||
suit = foundat.cap.suit
|
suit = foundat.cap.suit
|
||||||
if "CSHD"[suit] == gm[0]:
|
if "CSHD"[suit] == gm[0]:
|
||||||
for r in range("0A23456789TJQK".index(gm[1])):
|
for r in range(("0" + RANKS_S).index(gm[1])):
|
||||||
put(foundat, suit, r)
|
put(foundat, suit, r)
|
||||||
break
|
break
|
||||||
continue
|
continue
|
||||||
m = re.match(r'^(?:FC:|Freecells:)\s*(.*)', line)
|
m = re.match(r'^(?:FC:|Freecells:)\s*(.*)', line)
|
||||||
if m:
|
if m:
|
||||||
g = re.findall(
|
g = re.findall(
|
||||||
r'\b((?:[A23456789TJQK][HCDS])|\-)\b', m.group(1))
|
r'\b((?:' + CARD_RE + r')|\-)\b', m.group(1))
|
||||||
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):
|
||||||
|
@ -864,7 +869,7 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
if str_ != '-':
|
if str_ != '-':
|
||||||
put_str(game.reserves[i], str_)
|
put_str(game.reserves[i], str_)
|
||||||
continue
|
continue
|
||||||
g = re.findall(r'\b((?:[A23456789TJQK][HCDS]))\b', line)
|
g = re.findall(r'\b((?:' + CARD_RE + r'))\b', line)
|
||||||
for str_ in g:
|
for str_ in g:
|
||||||
put_str(game.rows[stack_idx], str_)
|
put_str(game.rows[stack_idx], str_)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue