mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
refactoring: del some unhelpful comments
This commit is contained in:
parent
b518678d8d
commit
7eb29a216f
1 changed files with 4 additions and 41 deletions
|
@ -22,14 +22,12 @@
|
||||||
# ---------------------------------------------------------------------------##
|
# ---------------------------------------------------------------------------##
|
||||||
|
|
||||||
|
|
||||||
# imports
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
# PySol imports
|
|
||||||
from pysollib.mfxutil import destruct
|
from pysollib.mfxutil import destruct
|
||||||
from pysollib.pysolrandom import constructRandom
|
from pysollib.pysolrandom import constructRandom
|
||||||
from pysollib.settings import DEBUG, FCS_COMMAND
|
from pysollib.settings import DEBUG, FCS_COMMAND
|
||||||
|
@ -704,7 +702,6 @@ class Yukon_Hint(YukonType_Hint):
|
||||||
return score + bonus, color
|
return score + bonus, color
|
||||||
|
|
||||||
|
|
||||||
# FIXME
|
|
||||||
class FreeCellType_Hint(CautiousDefaultHint):
|
class FreeCellType_Hint(CautiousDefaultHint):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -729,10 +726,6 @@ class PySolHintLayoutImportError(Exception):
|
||||||
return self.msg + ":\n\n" + ', '.join(self.cards)
|
return self.msg + ":\n\n" + ', '.join(self.cards)
|
||||||
|
|
||||||
|
|
||||||
# ************************************************************************
|
|
||||||
# * FreeCell-Solver
|
|
||||||
# ************************************************************************
|
|
||||||
|
|
||||||
class Base_Solver_Hint:
|
class Base_Solver_Hint:
|
||||||
def __init__(self, game, dialog, **game_type):
|
def __init__(self, game, dialog, **game_type):
|
||||||
self.game = game
|
self.game = game
|
||||||
|
@ -752,8 +745,6 @@ class Base_Solver_Hint:
|
||||||
self.base_rank = game_type['base_rank']
|
self.base_rank = game_type['base_rank']
|
||||||
else:
|
else:
|
||||||
self.base_rank = game.s.foundations[0].cap.base_rank
|
self.base_rank = game.s.foundations[0].cap.base_rank
|
||||||
# print 'game_type:', game_type
|
|
||||||
# print 'base_rank:', self.base_rank
|
|
||||||
|
|
||||||
def _setText(self, **kw):
|
def _setText(self, **kw):
|
||||||
return self.dialog.setText(**kw)
|
return self.dialog.setText(**kw)
|
||||||
|
@ -783,7 +774,6 @@ class Base_Solver_Hint:
|
||||||
if taken_hint and taken_hint[6]:
|
if taken_hint and taken_hint[6]:
|
||||||
return [taken_hint[6]]
|
return [taken_hint[6]]
|
||||||
h = self.hints[self.hints_index]
|
h = self.hints[self.hints_index]
|
||||||
# print 'getHints', taken_hint, h
|
|
||||||
if h is None:
|
if h is None:
|
||||||
return None
|
return None
|
||||||
ncards, src, dest = h
|
ncards, src, dest = h
|
||||||
|
@ -796,10 +786,7 @@ class Base_Solver_Hint:
|
||||||
if src is self.game.s.talon:
|
if src is self.game.s.talon:
|
||||||
if not src.cards[-1].face_up:
|
if not src.cards[-1].face_up:
|
||||||
self.game.flipMove(src)
|
self.game.flipMove(src)
|
||||||
# src.prepareStack()
|
|
||||||
# src.dealCards()
|
|
||||||
dest = self.game.s.foundations[0]
|
dest = self.game.s.foundations[0]
|
||||||
# skip = True
|
|
||||||
else:
|
else:
|
||||||
cards = src.cards[-ncards:]
|
cards = src.cards[-ncards:]
|
||||||
for f in self.game.s.foundations:
|
for f in self.game.s.foundations:
|
||||||
|
@ -811,7 +798,6 @@ class Base_Solver_Hint:
|
||||||
if skip:
|
if skip:
|
||||||
return []
|
return []
|
||||||
hint = (999999, 0, ncards, src, dest, None, thint)
|
hint = (999999, 0, ncards, src, dest, None, thint)
|
||||||
# print hint
|
|
||||||
return [hint]
|
return [hint]
|
||||||
|
|
||||||
def colonPrefixMatch(self, prefix, s):
|
def colonPrefixMatch(self, prefix, s):
|
||||||
|
@ -988,8 +974,6 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
game = self.game
|
game = self.game
|
||||||
self.board = ''
|
self.board = ''
|
||||||
is_simple_simon = self._isSimpleSimon()
|
is_simple_simon = self._isSimpleSimon()
|
||||||
#
|
|
||||||
#
|
|
||||||
b = ''
|
b = ''
|
||||||
for s in game.s.foundations:
|
for s in game.s.foundations:
|
||||||
if s.cards:
|
if s.cards:
|
||||||
|
@ -1030,12 +1014,9 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
progress = self.options['progress']
|
progress = self.options['progress']
|
||||||
|
|
||||||
board = self.calcBoardString()
|
board = self.calcBoardString()
|
||||||
#
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print('--------------------\n', board, '--------------------')
|
print('--------------------\n', board, '--------------------')
|
||||||
#
|
|
||||||
args = []
|
args = []
|
||||||
# args += ['-sam', '-p', '-opt', '--display-10-as-t']
|
|
||||||
if use_fc_solve_lib:
|
if use_fc_solve_lib:
|
||||||
args += ['--reset', '-opt', ]
|
args += ['--reset', '-opt', ]
|
||||||
else:
|
else:
|
||||||
|
@ -1046,7 +1027,6 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
args += ['--iter-output']
|
args += ['--iter-output']
|
||||||
fcs_iter_output_step = None
|
fcs_iter_output_step = None
|
||||||
if FCS_VERSION >= (4, 20, 0):
|
if FCS_VERSION >= (4, 20, 0):
|
||||||
# fcs_iter_output_step = 10000
|
|
||||||
fcs_iter_output_step = self.options['iters_step']
|
fcs_iter_output_step = self.options['iters_step']
|
||||||
args += ['--iter-output-step', str(fcs_iter_output_step)]
|
args += ['--iter-output-step', str(fcs_iter_output_step)]
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
|
@ -1058,7 +1038,6 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
'--stacks-num', str(len(game.s.rows)),
|
'--stacks-num', str(len(game.s.rows)),
|
||||||
'--freecells-num', str(len(game.s.reserves)),
|
'--freecells-num', str(len(game.s.reserves)),
|
||||||
]
|
]
|
||||||
#
|
|
||||||
if 'preset' in game_type:
|
if 'preset' in game_type:
|
||||||
args += ['--preset', game_type['preset']]
|
args += ['--preset', game_type['preset']]
|
||||||
if 'sbb' in game_type:
|
if 'sbb' in game_type:
|
||||||
|
@ -1069,14 +1048,12 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
args += ['--empty-stacks-filled-by', game_type['esf']]
|
args += ['--empty-stacks-filled-by', game_type['esf']]
|
||||||
|
|
||||||
if use_fc_solve_lib:
|
if use_fc_solve_lib:
|
||||||
# print(args)
|
|
||||||
fc_solve_lib_obj.input_cmd_line(args)
|
fc_solve_lib_obj.input_cmd_line(args)
|
||||||
status = fc_solve_lib_obj.solve_board(board)
|
status = fc_solve_lib_obj.solve_board(board)
|
||||||
else:
|
else:
|
||||||
command = FCS_COMMAND+' '+' '.join(args)
|
command = FCS_COMMAND+' '+' '.join(args)
|
||||||
pout, perr = self.run_solver(command, board)
|
pout, perr = self.run_solver(command, board)
|
||||||
self.solver_state = 'unknown'
|
self.solver_state = 'unknown'
|
||||||
#
|
|
||||||
stack_types = {
|
stack_types = {
|
||||||
'the': game.s.foundations,
|
'the': game.s.foundations,
|
||||||
'stack': game.s.rows,
|
'stack': game.s.rows,
|
||||||
|
@ -1085,7 +1062,6 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
if not(use_fc_solve_lib) and progress:
|
if not(use_fc_solve_lib) and progress:
|
||||||
# iteration output
|
|
||||||
iter_ = 0
|
iter_ = 0
|
||||||
depth = 0
|
depth = 0
|
||||||
states = 0
|
states = 0
|
||||||
|
@ -1186,33 +1162,25 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
|
||||||
|
|
||||||
st = stack_types[m.group('source_type')]
|
st = stack_types[m.group('source_type')]
|
||||||
sn = int(m.group('source_idx'))
|
sn = int(m.group('source_idx'))
|
||||||
src = st[sn] # source stack
|
src = st[sn]
|
||||||
|
|
||||||
dest_s = m.group('dest')
|
dest_s = m.group('dest')
|
||||||
if dest_s == 'the foundations':
|
if dest_s == 'the foundations':
|
||||||
# to foundation
|
|
||||||
dest = None
|
dest = None
|
||||||
else:
|
else:
|
||||||
# to rows or reserves
|
|
||||||
dt = stack_types[m.group('dest_type')]
|
dt = stack_types[m.group('dest_type')]
|
||||||
dn = int(m.group('dest_idx'))
|
dest = dt[int(m.group('dest_idx'))]
|
||||||
dest = dt[dn]
|
|
||||||
|
|
||||||
hints.append([ncards, src, dest])
|
hints.append([ncards, src, dest])
|
||||||
# print src, dest, ncards
|
|
||||||
|
|
||||||
#
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print('time:', time.time()-start_time)
|
print('time:', time.time()-start_time)
|
||||||
# print perr.read(),
|
|
||||||
|
|
||||||
self.hints = hints
|
self.hints = hints
|
||||||
if len(hints) > 0:
|
if len(hints) > 0:
|
||||||
if self.solver_state != 'intractable':
|
if self.solver_state != 'intractable':
|
||||||
self.solver_state = 'solved'
|
self.solver_state = 'solved'
|
||||||
self.hints.append(None) # XXX
|
self.hints.append(None)
|
||||||
|
|
||||||
# print self.hints
|
|
||||||
|
|
||||||
if not use_fc_solve_lib:
|
if not use_fc_solve_lib:
|
||||||
pout.close()
|
pout.close()
|
||||||
|
@ -1251,28 +1219,23 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
|
||||||
game_type = self.game_type
|
game_type = self.game_type
|
||||||
|
|
||||||
board = self.calcBoardString()
|
board = self.calcBoardString()
|
||||||
#
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print('--------------------\n', board, '--------------------')
|
print('--------------------\n', board, '--------------------')
|
||||||
#
|
|
||||||
args = []
|
args = []
|
||||||
# args += ['-sam', '-p', '-opt', '--display-10-as-t']
|
|
||||||
args += ['--game', game_type['preset'], '--rank-reach-prune']
|
args += ['--game', game_type['preset'], '--rank-reach-prune']
|
||||||
args += ['--max-iters', str(self.options['max_iters'])]
|
args += ['--max-iters', str(self.options['max_iters'])]
|
||||||
if 'queens_on_kings' in game_type:
|
if 'queens_on_kings' in game_type:
|
||||||
args += ['--queens-on-kings']
|
args += ['--queens-on-kings']
|
||||||
if 'wrap_ranks' in game_type:
|
if 'wrap_ranks' in game_type:
|
||||||
args += ['--wrap-ranks']
|
args += ['--wrap-ranks']
|
||||||
#
|
|
||||||
|
|
||||||
command = self.BLACK_HOLE_SOLVER_COMMAND + ' ' + ' '.join(args)
|
command = self.BLACK_HOLE_SOLVER_COMMAND + ' ' + ' '.join(args)
|
||||||
pout, perr = self.run_solver(command, board)
|
pout, perr = self.run_solver(command, board)
|
||||||
#
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
result = ''
|
result = ''
|
||||||
# iteration output
|
|
||||||
|
|
||||||
for sbytes in pout:
|
for sbytes in pout:
|
||||||
s = six.text_type(sbytes, encoding='utf-8')
|
s = six.text_type(sbytes, encoding='utf-8')
|
||||||
|
|
Loading…
Add table
Reference in a new issue