diff --git a/pysollib/hint.py b/pysollib/hint.py index 08798206..bfe0257e 100644 --- a/pysollib/hint.py +++ b/pysollib/hint.py @@ -1011,14 +1011,17 @@ class FreeCellSolver_Hint(Base_Solver_Hint): game_type = self.game_type global FCS_VERSION if FCS_VERSION is None: - 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))) + if use_fc_solve_lib: + FCS_VERSION = (5, 0, 0) 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'] diff --git a/pysollib/init.py b/pysollib/init.py index 44cbfd40..3d658c4e 100644 --- a/pysollib/init.py +++ b/pysollib/init.py @@ -138,21 +138,30 @@ def init(): os.environ['FREECELL_SOLVER_PRESETRC'] = f if os.name in ('posix', 'nt'): try: - 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'): + try: + import freecell_solver + fc_solve_lib_obj = freecell_solver.FreecellSolver() + assert fc_solve_lib_obj pysollib.settings.USE_FREECELL_SOLVER = True - if os.name == 'posix': - os.wait() # kill zombi + except Exception: + 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: # traceback.print_exc() pass