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:
parent
653e84b049
commit
fee9f6e20e
1 changed files with 87 additions and 58 deletions
|
@ -1052,6 +1052,16 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
if 'esf' in game_type:
|
if 'esf' in game_type:
|
||||||
args += ['--empty-stacks-filled-by', game_type['esf']]
|
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])
|
command = FCS_COMMAND+' '+' '.join([str(i) for i in args])
|
||||||
pout, perr = self.run_solver(command, board)
|
pout, perr = self.run_solver(command, board)
|
||||||
self.solver_state = 'unknown'
|
self.solver_state = 'unknown'
|
||||||
|
@ -1090,13 +1100,30 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
self.dialog.setText(iter=iter_, depth=depth, states=states)
|
self.dialog.setText(iter=iter_, depth=depth, states=states)
|
||||||
|
|
||||||
hints = []
|
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:
|
for sbytes in pout:
|
||||||
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 self._determineIfSolverState(s):
|
if self._determineIfSolverState(s):
|
||||||
next
|
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:
|
if m:
|
||||||
iter_ = int(m.group(1))
|
iter_ = int(m.group(1))
|
||||||
self.dialog.setText(iter=iter_)
|
self.dialog.setText(iter=iter_)
|
||||||
|
@ -1128,7 +1155,8 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
'(?P<ncards>a card|(?P<count>[0-9]+) cards) '
|
'(?P<ncards>a card|(?P<count>[0-9]+) cards) '
|
||||||
'from (?P<source_type>stack|freecell) '
|
'from (?P<source_type>stack|freecell) '
|
||||||
'(?P<source_idx>[0-9]+) to '
|
'(?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)
|
'(?P<dest_idx>[0-9]+))\\s*', move_s)
|
||||||
|
|
||||||
if not m:
|
if not m:
|
||||||
|
@ -1170,6 +1198,7 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
|
|
||||||
# print self.hints
|
# print self.hints
|
||||||
|
|
||||||
|
if not use_lib:
|
||||||
pout.close()
|
pout.close()
|
||||||
perr.close()
|
perr.close()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue