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,8 +1052,18 @@ 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']]
command = FCS_COMMAND+' '+' '.join([str(i) for i in args]) use_lib = True
pout, perr = self.run_solver(command, board) 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' self.solver_state = 'unknown'
# #
stack_types = { stack_types = {
@ -1090,71 +1100,89 @@ 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 = []
for sbytes in pout: if use_lib:
s = six.text_type(sbytes, encoding='utf-8') m = obj.get_next_move()
if DEBUG: while m:
print(s) type_ = ord(m.s[0])
if self._determineIfSolverState(s): src = ord(m.s[1])
next dest = ord(m.s[2])
m = re.match('Total number of states checked is ([0-9]+)\\.', s) hints.append([
if m: 1, # ord(m.s[3]),
iter_ = int(m.group(1)) (game.s.rows if (type_ in [0, 1, 4])
self.dialog.setText(iter=iter_) 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 = re.match('This scan generated ([0-9]+) states\\.', s) m = obj.get_next_move()
else:
if m: for sbytes in pout:
states = int(m.group(1)) s = six.text_type(sbytes, encoding='utf-8')
self.dialog.setText(states=states) if DEBUG:
print(s)
m = re.match('Move (.*)', s) if self._determineIfSolverState(s):
if not m: next
continue
move_s = m.group(1)
m = re.match(
'the sequence on top of Stack ([0-9]+) to the foundations',
move_s)
if m:
ncards = 13
st = stack_types['stack']
sn = int(m.group(1))
src = st[sn]
dest = None
else:
m = re.match( m = re.match(
'(?P<ncards>a card|(?P<count>[0-9]+) cards) ' 'Total number of states checked is ([0-9]+)\\.', s)
'from (?P<source_type>stack|freecell) ' if m:
'(?P<source_idx>[0-9]+) to ' iter_ = int(m.group(1))
'(?P<dest>the foundations|(?P<dest_type>freecell|stack) ' self.dialog.setText(iter=iter_)
'(?P<dest_idx>[0-9]+))\\s*', move_s)
m = re.match('This scan generated ([0-9]+) states\\.', s)
if m:
states = int(m.group(1))
self.dialog.setText(states=states)
m = re.match('Move (.*)', s)
if not m: if not m:
continue continue
ncards = m.group('ncards') move_s = m.group(1)
if ncards == 'a card':
ncards = 1
else:
ncards = int(m.group('count'))
st = stack_types[m.group('source_type')] m = re.match(
sn = int(m.group('source_idx')) 'the sequence on top of Stack ([0-9]+) to the foundations',
src = st[sn] # source stack move_s)
dest_s = m.group('dest') if m:
if dest_s == 'the foundations': ncards = 13
# to foundation st = stack_types['stack']
sn = int(m.group(1))
src = st[sn]
dest = None dest = None
else: else:
# to rows or reserves m = re.match(
dt = stack_types[m.group('dest_type')] '(?P<ncards>a card|(?P<count>[0-9]+) cards) '
dn = int(m.group('dest_idx')) 'from (?P<source_type>stack|freecell) '
dest = dt[dn] '(?P<source_idx>[0-9]+) to '
'(?P<dest>the foundations|'
'(?P<dest_type>freecell|stack) '
'(?P<dest_idx>[0-9]+))\\s*', move_s)
hints.append([ncards, src, dest]) if not m:
continue
ncards = m.group('ncards')
if ncards == 'a card':
ncards = 1
else:
ncards = int(m.group('count'))
st = stack_types[m.group('source_type')]
sn = int(m.group('source_idx'))
src = st[sn] # source stack
dest_s = m.group('dest')
if dest_s == 'the foundations':
# to foundation
dest = None
else:
# to rows or reserves
dt = stack_types[m.group('dest_type')]
dn = int(m.group('dest_idx'))
dest = dt[dn]
hints.append([ncards, src, dest])
# print src, dest, ncards # print src, dest, ncards
# #
@ -1170,8 +1198,9 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
# print self.hints # print self.hints
pout.close() if not use_lib:
perr.close() pout.close()
perr.close()
class BlackHoleSolver_Hint(Base_Solver_Hint): class BlackHoleSolver_Hint(Base_Solver_Hint):