1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Refactoring / code cleanup.

See:

* https://en.wikipedia.org/wiki/Code_refactoring

* https://www.refactoring.com/

* https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/

Some small optimisations may have slipped in as well.
This commit is contained in:
Shlomi Fish 2020-06-17 13:48:48 +03:00
parent 14d4c0c509
commit d9efba4456

View file

@ -1132,18 +1132,16 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
if DEBUG: if DEBUG:
print(s) print(s)
if self._determineIfSolverState(s): if self._determineIfSolverState(s):
next break
m = re.match( m = re.match(
'Total number of states checked is ([0-9]+)\\.', s) 'Total number of states checked is ([0-9]+)\\.', s)
if m: if m:
iter_ = int(m.group(1)) self.dialog.setText(iter=int(m.group(1)))
self.dialog.setText(iter=iter_)
m = re.match('This scan generated ([0-9]+) states\\.', s) m = re.match('This scan generated ([0-9]+) states\\.', s)
if m: if m:
states = int(m.group(1)) self.dialog.setText(states=int(m.group(1)))
self.dialog.setText(states=states)
m = re.match('Move (.*)', s) m = re.match('Move (.*)', s)
if not m: if not m:
@ -1173,8 +1171,7 @@ class FreeCellSolver_Hint(Base_Solver_Hint):
if not m: if not m:
continue continue
ncards = m.group('ncards') if m.group('ncards') == 'a card':
if ncards == 'a card':
ncards = 1 ncards = 1
else: else:
ncards = int(m.group('count')) ncards = int(m.group('count'))
@ -1253,15 +1250,14 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
args = [] args = []
# args += ['-sam', '-p', '-opt', '--display-10-as-t'] # 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', 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 + ' ' + \ command = self.BLACK_HOLE_SOLVER_COMMAND + ' ' + ' '.join(args)
' '.join([str(i) for i in args])
pout, perr = self.run_solver(command, board) pout, perr = self.run_solver(command, board)
# #
if DEBUG: if DEBUG:
@ -1298,15 +1294,13 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
m = re.match('Total number of states checked is ([0-9]+)\\.', s) m = re.match('Total number of states checked is ([0-9]+)\\.', s)
if m: if m:
iter_ = int(m.group(1)) self.dialog.setText(iter=int(m.group(1)))
self.dialog.setText(iter=iter_)
continue continue
m = re.match('This scan generated ([0-9]+) states\\.', s) m = re.match('This scan generated ([0-9]+) states\\.', s)
if m: if m:
states = int(m.group(1)) self.dialog.setText(states=int(m.group(1)))
self.dialog.setText(states=states)
continue continue
m = re.match( m = re.match(
@ -1315,24 +1309,15 @@ class BlackHoleSolver_Hint(Base_Solver_Hint):
continue continue
found_stack_idx = int(m.group(1)) found_stack_idx = int(m.group(1))
ncards = 1 src = game.s.rows[found_stack_idx]
st = game.s.rows
sn = found_stack_idx
src = st[sn] # source stack
dest = None
hints.append([ncards, src, dest]) hints.append([1, src, None])
# print src, dest, ncards
#
if DEBUG: if DEBUG:
print('time:', time.time()-start_time) print('time:', time.time()-start_time)
# print perr.read(),
hints.append(None)
self.hints = hints self.hints = hints
self.hints.append(None) # XXX
# print self.hints
pout.close() pout.close()
perr.close() perr.close()