mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-15 02:54:09 -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)
|
WasteStack.__init__(self, x, y, game, **cap)
|
||||||
|
|
||||||
def acceptsCards(self, from_stack, cards):
|
def acceptsCards(self, from_stack, cards):
|
||||||
|
if from_stack is self.game.s.talon:
|
||||||
|
return True
|
||||||
if not WasteStack.acceptsCards(self, from_stack, cards):
|
if not WasteStack.acceptsCards(self, from_stack, cards):
|
||||||
return False
|
return False
|
||||||
# check cards
|
# check cards
|
||||||
|
@ -129,6 +131,8 @@ class Golf_RowStack(BasicRowStack):
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
||||||
class Golf(Game):
|
class Golf(Game):
|
||||||
|
Solver_Class = BlackHoleSolverWrapper(preset='golf', base_rank=0,
|
||||||
|
queens_on_kings=True)
|
||||||
Waste_Class = Golf_Waste
|
Waste_Class = Golf_Waste
|
||||||
Hint_Class = Golf_Hint
|
Hint_Class = Golf_Hint
|
||||||
|
|
||||||
|
@ -201,6 +205,8 @@ class Golf(Game):
|
||||||
# ************************************************************************
|
# ************************************************************************
|
||||||
|
|
||||||
class DeadKingGolf(Golf):
|
class DeadKingGolf(Golf):
|
||||||
|
Solver_Class = BlackHoleSolverWrapper(preset='golf', base_rank=0)
|
||||||
|
|
||||||
def getStrictness(self):
|
def getStrictness(self):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -211,6 +217,8 @@ class DeadKingGolf(Golf):
|
||||||
|
|
||||||
|
|
||||||
class RelaxedGolf(Golf):
|
class RelaxedGolf(Golf):
|
||||||
|
Solver_Class = BlackHoleSolverWrapper(preset='golf', base_rank=0,
|
||||||
|
wrap_ranks=True)
|
||||||
Waste_Class = StackWrapper(Golf_Waste, mod=13)
|
Waste_Class = StackWrapper(Golf_Waste, mod=13)
|
||||||
|
|
||||||
shallHighlightMatch = Game._shallHighlightMatch_RKW
|
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:
|
if len(src.cards) > ncards and not src.cards[-ncards-1].face_up:
|
||||||
# flip card
|
# flip card
|
||||||
thint = (999999, 0, 1, src, src, None, None)
|
thint = (999999, 0, 1, src, src, None, None)
|
||||||
|
skip = False
|
||||||
if dest is None: # foundation
|
if dest is None: # foundation
|
||||||
cards = src.cards[-ncards:]
|
if src is self.game.s.talon:
|
||||||
for f in self.game.s.foundations:
|
if not src.cards[-1].face_up:
|
||||||
if f.acceptsCards(src, cards):
|
self.game.flipMove(src)
|
||||||
dest = f
|
# src.prepareStack()
|
||||||
break
|
# 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
|
assert dest
|
||||||
hint = (999999, 0, ncards, src, dest, None, thint)
|
|
||||||
self.hints_index += 1
|
self.hints_index += 1
|
||||||
|
if skip:
|
||||||
|
return []
|
||||||
|
hint = (999999, 0, ncards, src, dest, None, thint)
|
||||||
# print hint
|
# print hint
|
||||||
return [hint]
|
return [hint]
|
||||||
|
|
||||||
|
@ -1168,6 +1179,11 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
||||||
|
|
||||||
def calcBoardString(self):
|
def calcBoardString(self):
|
||||||
board = ''
|
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
|
cards = self.game.s.foundations[0].cards
|
||||||
s = '-'
|
s = '-'
|
||||||
if (len(cards) > 0):
|
if (len(cards) > 0):
|
||||||
|
@ -1198,6 +1214,10 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
||||||
# args += ['-sam', '-p', '-opt', '--display-10-as-t']
|
# args += ['-sam', '-p', '-opt', '--display-10-as-t']
|
||||||
args += ['--game', game_type['preset'], '--rank-reach-prune']
|
args += ['--game', game_type['preset'], '--rank-reach-prune']
|
||||||
args += ['--max-iters', self.options['max_iters']]
|
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 + ' ' + \
|
command = self.BLACK_HOLE_SOLVER_COMMAND + ' ' + \
|
||||||
|
@ -1231,6 +1251,11 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
||||||
s = six.text_type(sbytes, encoding='utf-8')
|
s = six.text_type(sbytes, encoding='utf-8')
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print(s)
|
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)
|
m = re.match('Total number of states checked is ([0-9]+)\\.', s)
|
||||||
if m:
|
if m:
|
||||||
iter_ = int(m.group(1))
|
iter_ = int(m.group(1))
|
||||||
|
|
Loading…
Add table
Reference in a new issue