mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Use freecell-solver wo which fc-solve
.
No need for the executable if freecell_solver.py exists and can be instantiated.
This commit is contained in:
parent
bb8785e76b
commit
e9e19afc46
2 changed files with 33 additions and 21 deletions
|
@ -1011,14 +1011,17 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
game_type = self.game_type
|
game_type = self.game_type
|
||||||
global FCS_VERSION
|
global FCS_VERSION
|
||||||
if FCS_VERSION is None:
|
if FCS_VERSION is None:
|
||||||
pout, _ = self.run_solver(FCS_COMMAND + ' --version', '')
|
if use_fc_solve_lib:
|
||||||
s = six.text_type(pout.read(), encoding='utf-8')
|
FCS_VERSION = (5, 0, 0)
|
||||||
m = re.search(r'version ([0-9]+)\.([0-9]+)\.([0-9]+)', s)
|
|
||||||
if m:
|
|
||||||
FCS_VERSION = (int(m.group(1)), int(m.group(2)),
|
|
||||||
int(m.group(3)))
|
|
||||||
else:
|
else:
|
||||||
FCS_VERSION = (0, 0, 0)
|
pout, _ = self.run_solver(FCS_COMMAND + ' --version', '')
|
||||||
|
s = six.text_type(pout.read(), encoding='utf-8')
|
||||||
|
m = re.search(r'version ([0-9]+)\.([0-9]+)\.([0-9]+)', s)
|
||||||
|
if m:
|
||||||
|
FCS_VERSION = (int(m.group(1)), int(m.group(2)),
|
||||||
|
int(m.group(3)))
|
||||||
|
else:
|
||||||
|
FCS_VERSION = (0, 0, 0)
|
||||||
|
|
||||||
progress = self.options['progress']
|
progress = self.options['progress']
|
||||||
|
|
||||||
|
|
|
@ -138,21 +138,30 @@ def init():
|
||||||
os.environ['FREECELL_SOLVER_PRESETRC'] = f
|
os.environ['FREECELL_SOLVER_PRESETRC'] = f
|
||||||
if os.name in ('posix', 'nt'):
|
if os.name in ('posix', 'nt'):
|
||||||
try:
|
try:
|
||||||
kw = {'shell': True,
|
try:
|
||||||
'stdout': subprocess.PIPE,
|
import freecell_solver
|
||||||
'stderr': subprocess.PIPE,
|
fc_solve_lib_obj = freecell_solver.FreecellSolver()
|
||||||
'stdin': subprocess.PIPE, }
|
assert fc_solve_lib_obj
|
||||||
if os.name != 'nt':
|
|
||||||
kw['close_fds'] = True
|
|
||||||
p = subprocess.Popen(pysollib.settings.FCS_COMMAND+' --help', **kw)
|
|
||||||
p.stdin.close()
|
|
||||||
line = p.stdout.readline()
|
|
||||||
if sys.version_info >= (3,):
|
|
||||||
line = line.decode("utf-8")
|
|
||||||
if line.startswith('fc-solve'):
|
|
||||||
pysollib.settings.USE_FREECELL_SOLVER = True
|
pysollib.settings.USE_FREECELL_SOLVER = True
|
||||||
if os.name == 'posix':
|
except Exception:
|
||||||
os.wait() # kill zombi
|
pass
|
||||||
|
if not pysollib.settings.USE_FREECELL_SOLVER:
|
||||||
|
kw = {'shell': True,
|
||||||
|
'stdout': subprocess.PIPE,
|
||||||
|
'stderr': subprocess.PIPE,
|
||||||
|
'stdin': subprocess.PIPE, }
|
||||||
|
if os.name != 'nt':
|
||||||
|
kw['close_fds'] = True
|
||||||
|
p = subprocess.Popen(
|
||||||
|
pysollib.settings.FCS_COMMAND+' --help', **kw)
|
||||||
|
p.stdin.close()
|
||||||
|
line = p.stdout.readline()
|
||||||
|
if sys.version_info >= (3,):
|
||||||
|
line = line.decode("utf-8")
|
||||||
|
if line.startswith('fc-solve'):
|
||||||
|
pysollib.settings.USE_FREECELL_SOLVER = True
|
||||||
|
if os.name == 'posix':
|
||||||
|
os.wait() # kill zombi
|
||||||
except Exception:
|
except Exception:
|
||||||
# traceback.print_exc()
|
# traceback.print_exc()
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Add table
Reference in a new issue