1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

WiP support for using solvers' DLLs

This commit is contained in:
Shlomi Fish 2020-06-16 22:29:42 +03:00
parent 653e84b049
commit fee9f6e20e

View file

@ -1052,6 +1052,16 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
if 'esf' in game_type:
args += ['--empty-stacks-filled-by', game_type['esf']]
use_lib = True
if use_lib:
import freecell_solver
obj = freecell_solver.FreecellSolver()
print(args)
obj.input_cmd_line([str(s) for s in args])
status = obj.solve_board(board)
if status != 0:
assert 0
else:
command = FCS_COMMAND+' '+' '.join([str(i) for i in args])
pout, perr = self.run_solver(command, board)
self.solver_state = 'unknown'
@ -1090,13 +1100,30 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
self.dialog.setText(iter=iter_, depth=depth, states=states)
hints = []
if use_lib:
m = obj.get_next_move()
while m:
type_ = ord(m.s[0])
src = ord(m.s[1])
dest = ord(m.s[2])
hints.append([
1, # ord(m.s[3]),
(game.s.rows if (type_ in [0, 1, 4])
else game.s.reserves)[src],
(game.s.rows[dest] if (type_ in [0, 2])
else (game.s.reserves[dest]
if (type_ in [1, 3]) else None))])
m = obj.get_next_move()
else:
for sbytes in pout:
s = six.text_type(sbytes, encoding='utf-8')
if DEBUG:
print(s)
if self._determineIfSolverState(s):
next
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:
iter_ = int(m.group(1))
self.dialog.setText(iter=iter_)
@ -1128,7 +1155,8 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
'(?P<ncards>a card|(?P<count>[0-9]+) cards) '
'from (?P<source_type>stack|freecell) '
'(?P<source_idx>[0-9]+) to '
'(?P<dest>the foundations|(?P<dest_type>freecell|stack) '
'(?P<dest>the foundations|'
'(?P<dest_type>freecell|stack) '
'(?P<dest_idx>[0-9]+))\\s*', move_s)
if not m:
@ -1170,6 +1198,7 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
# print self.hints
if not use_lib:
pout.close()
perr.close()