mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Move duplicate code to the parent class
This commit is contained in:
parent
ca48ec221d
commit
6f72b4df3b
1 changed files with 20 additions and 30 deletions
|
@ -791,6 +791,24 @@ class Base_Solver_Hint:
|
||||||
self._v = None
|
self._v = None
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def start_solver(self, command, board):
|
||||||
|
if DEBUG:
|
||||||
|
print(command)
|
||||||
|
kw = {'shell': True,
|
||||||
|
'stdin': subprocess.PIPE,
|
||||||
|
'stdout': subprocess.PIPE,
|
||||||
|
'stderr': subprocess.PIPE}
|
||||||
|
if os.name != 'nt':
|
||||||
|
kw['close_fds'] = True
|
||||||
|
p = subprocess.Popen(command, **kw)
|
||||||
|
pin, pout, perr = p.stdin, p.stdout, p.stderr
|
||||||
|
bytes_board = board
|
||||||
|
if sys.version_info > (3,):
|
||||||
|
bytes_board = bytes(board, 'utf-8')
|
||||||
|
pin.write(bytes_board)
|
||||||
|
pin.close()
|
||||||
|
return pout, perr
|
||||||
|
|
||||||
|
|
||||||
class FreeCellSolver_Hint(Base_Solver_Hint):
|
class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
def _determineIfSolverState(self, line):
|
def _determineIfSolverState(self, line):
|
||||||
|
@ -951,21 +969,7 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
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])
|
command = FCS_COMMAND+' '+' '.join([str(i) for i in args])
|
||||||
if DEBUG:
|
pout, perr = self.start_solver(command, board)
|
||||||
print(command)
|
|
||||||
kw = {'shell': True,
|
|
||||||
'stdin': subprocess.PIPE,
|
|
||||||
'stdout': subprocess.PIPE,
|
|
||||||
'stderr': subprocess.PIPE}
|
|
||||||
if os.name != 'nt':
|
|
||||||
kw['close_fds'] = True
|
|
||||||
p = subprocess.Popen(command, **kw)
|
|
||||||
pin, pout, perr = p.stdin, p.stdout, p.stderr
|
|
||||||
bytes_board = board
|
|
||||||
if sys.version_info > (3,):
|
|
||||||
bytes_board = bytes(board, 'utf-8')
|
|
||||||
pin.write(bytes_board)
|
|
||||||
pin.close()
|
|
||||||
#
|
#
|
||||||
stack_types = {
|
stack_types = {
|
||||||
'the': game.s.foundations,
|
'the': game.s.foundations,
|
||||||
|
@ -1125,21 +1129,7 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
||||||
|
|
||||||
command = self.BLACK_HOLE_SOLVER_COMMAND + ' ' + \
|
command = self.BLACK_HOLE_SOLVER_COMMAND + ' ' + \
|
||||||
' '.join([str(i) for i in args])
|
' '.join([str(i) for i in args])
|
||||||
if DEBUG:
|
pout, perr = self.start_solver(command, board)
|
||||||
print(command)
|
|
||||||
kw = {'shell': True,
|
|
||||||
'stdin': subprocess.PIPE,
|
|
||||||
'stdout': subprocess.PIPE,
|
|
||||||
'stderr': subprocess.PIPE}
|
|
||||||
if os.name != 'nt':
|
|
||||||
kw['close_fds'] = True
|
|
||||||
p = subprocess.Popen(command, **kw)
|
|
||||||
pin, pout, perr = p.stdin, p.stdout, p.stderr
|
|
||||||
bytes_board = board
|
|
||||||
if sys.version_info > (3,):
|
|
||||||
bytes_board = bytes(board, 'utf-8')
|
|
||||||
pin.write(bytes_board)
|
|
||||||
pin.close()
|
|
||||||
#
|
#
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
Loading…
Add table
Reference in a new issue