From e4643f71e7a7ef29090e2f2f69565cd00a590213 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sat, 26 Jan 2019 18:43:58 +0200 Subject: [PATCH] add support for solving three golf variants. Using the BlackHoleSolverWrapper . See https://github.com/shlomif/PySolFC/issues/98 issue98. --- pysollib/games/golf.py | 8 ++++++++ pysollib/hint.py | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/pysollib/games/golf.py b/pysollib/games/golf.py index 5c2e7122..b1bd9c51 100644 --- a/pysollib/games/golf.py +++ b/pysollib/games/golf.py @@ -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 diff --git a/pysollib/hint.py b/pysollib/hint.py index e2b6f493..de0391af 100644 --- a/pysollib/hint.py +++ b/pysollib/hint.py @@ -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))