mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
add support for solving three golf variants.
Using the BlackHoleSolverWrapper . See https://github.com/shlomif/PySolFC/issues/98 issue98.
This commit is contained in:
parent
0c19541e8d
commit
e4643f71e7
2 changed files with 39 additions and 6 deletions
|
@ -102,6 +102,8 @@ class Golf_Waste(WasteStack):
|
|||
WasteStack.__init__(self, x, y, game, **cap)
|
||||
|
||||
def acceptsCards(self, from_stack, cards):
|
||||
if from_stack is self.game.s.talon:
|
||||
return True
|
||||
if not WasteStack.acceptsCards(self, from_stack, cards):
|
||||
return False
|
||||
# check cards
|
||||
|
@ -129,6 +131,8 @@ class Golf_RowStack(BasicRowStack):
|
|||
# ************************************************************************
|
||||
|
||||
class Golf(Game):
|
||||
Solver_Class = BlackHoleSolverWrapper(preset='golf', base_rank=0,
|
||||
queens_on_kings=True)
|
||||
Waste_Class = Golf_Waste
|
||||
Hint_Class = Golf_Hint
|
||||
|
||||
|
@ -201,6 +205,8 @@ class Golf(Game):
|
|||
# ************************************************************************
|
||||
|
||||
class DeadKingGolf(Golf):
|
||||
Solver_Class = BlackHoleSolverWrapper(preset='golf', base_rank=0)
|
||||
|
||||
def getStrictness(self):
|
||||
return 1
|
||||
|
||||
|
@ -211,6 +217,8 @@ class DeadKingGolf(Golf):
|
|||
|
||||
|
||||
class RelaxedGolf(Golf):
|
||||
Solver_Class = BlackHoleSolverWrapper(preset='golf', base_rank=0,
|
||||
wrap_ranks=True)
|
||||
Waste_Class = StackWrapper(Golf_Waste, mod=13)
|
||||
|
||||
shallHighlightMatch = Game._shallHighlightMatch_RKW
|
||||
|
|
|
@ -788,15 +788,26 @@ class Base_Solver_Hint:
|
|||
if len(src.cards) > ncards and not src.cards[-ncards-1].face_up:
|
||||
# flip card
|
||||
thint = (999999, 0, 1, src, src, None, None)
|
||||
skip = False
|
||||
if dest is None: # foundation
|
||||
cards = src.cards[-ncards:]
|
||||
for f in self.game.s.foundations:
|
||||
if f.acceptsCards(src, cards):
|
||||
dest = f
|
||||
break
|
||||
if src is self.game.s.talon:
|
||||
if not src.cards[-1].face_up:
|
||||
self.game.flipMove(src)
|
||||
# src.prepareStack()
|
||||
# src.dealCards()
|
||||
dest = self.game.s.foundations[0]
|
||||
# skip = True
|
||||
else:
|
||||
cards = src.cards[-ncards:]
|
||||
for f in self.game.s.foundations:
|
||||
if f.acceptsCards(src, cards):
|
||||
dest = f
|
||||
break
|
||||
assert dest
|
||||
hint = (999999, 0, ncards, src, dest, None, thint)
|
||||
self.hints_index += 1
|
||||
if skip:
|
||||
return []
|
||||
hint = (999999, 0, ncards, src, dest, None, thint)
|
||||
# print hint
|
||||
return [hint]
|
||||
|
||||
|
@ -1168,6 +1179,11 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
|||
|
||||
def calcBoardString(self):
|
||||
board = ''
|
||||
cards = self.game.s.talon.cards
|
||||
if (len(cards) > 0):
|
||||
board += ' '.join(['Talon:'] +
|
||||
[self.card2str1(x) for x in reversed(cards)])
|
||||
board += '\n'
|
||||
cards = self.game.s.foundations[0].cards
|
||||
s = '-'
|
||||
if (len(cards) > 0):
|
||||
|
@ -1198,6 +1214,10 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
|||
# args += ['-sam', '-p', '-opt', '--display-10-as-t']
|
||||
args += ['--game', game_type['preset'], '--rank-reach-prune']
|
||||
args += ['--max-iters', self.options['max_iters']]
|
||||
if 'queens_on_kings' in game_type:
|
||||
args += ['--queens-on-kings']
|
||||
if 'wrap_ranks' in game_type:
|
||||
args += ['--wrap-ranks']
|
||||
#
|
||||
|
||||
command = self.BLACK_HOLE_SOLVER_COMMAND + ' ' + \
|
||||
|
@ -1231,6 +1251,11 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
|||
s = six.text_type(sbytes, encoding='utf-8')
|
||||
if DEBUG:
|
||||
print(s)
|
||||
|
||||
if s.strip() == 'Deal talon':
|
||||
hints.append([1, game.s.talon, None])
|
||||
continue
|
||||
|
||||
m = re.match('Total number of states checked is ([0-9]+)\\.', s)
|
||||
if m:
|
||||
iter_ = int(m.group(1))
|
||||
|
|
Loading…
Add table
Reference in a new issue