Commit 213ebb76 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Optimize strategy implementation:

- Instead of computing a complete score for each state, compute+compare
  the first component for each one, then the second, etc.
- Set colskip (and nrows) once and update occasionally once instead of
  constantly recomputing it.
- Add some more actions to do on the destination column.
- Fix move loop detection.
- Do not wait on bomb explosion (since they no longer cause loops).
parent a4129c62
......@@ -4,9 +4,10 @@ import time
from collections import deque
from itertools import count
from Xlib import error
from strategy import State
from detection import NOBLOCK
from interaction import get_exapunks_window, focus_window, screenshot_board, \
press_keys, listen_keys, KEY_DELAY
from strategy import State
MAX_SPEED_ROWS = 3
......@@ -33,7 +34,7 @@ if __name__ == '__main__':
listen_keys({'s': lambda: save_screenshot(win)})
solutions = deque([], maxlen=3)
buf = deque([], maxlen=3)
def vprint(*args, **kwargs):
if verbose:
......@@ -56,10 +57,10 @@ if __name__ == '__main__':
vprint()
start = time.time()
solution = state.solve()
newstate = state.solve()
end = time.time()
vprint('thought for', round((end - start) * 1000, 1), 'ms')
except (TypeError, AssertionError):
except (TypeError, AssertionError) as e:
vprint('\rerror during parsing, wait for a bit...', end='')
time.sleep(0.050)
continue
......@@ -68,33 +69,33 @@ if __name__ == '__main__':
time.sleep(0.500)
continue
if len(solutions) == 3 and solution.loops(solutions.popleft()):
if state.held == NOBLOCK and any(map(newstate.loops, buf)):
vprint('\rloop detected, wait for a bit...', end='')
time.sleep(0.03)
elif solution.moves:
vprint('moves:', solution.keys())
vprint(' score:', solution.score)
if solutions:
vprint('prev score:', solutions[-1].score)
elif newstate.moves:
vprint('moves:', newstate.keys())
vprint(' score:', newstate.score)
if buf:
vprint('prev score:', buf[-1].score)
vprint()
vprint('target after moves:')
vprint_state(solution.newstate)
vprint_state(newstate)
press_keys(win, solution.keys())
press_keys(win, newstate.keys())
#keys_delay = len(solution.moves) * 2 * KEY_DELAY
#moves_delay = max(0, solution.delay() - keys_delay)
#keys_delay = len(newstate.moves) * 2 * KEY_DELAY
#moves_delay = max(0, newstate.delay() - keys_delay)
#vprint('wait for', moves_delay, 'ms')
#time.sleep(moves_delay / 1000)
time.sleep(0.070)
elif state.nrows() - 2 <= MAX_SPEED_ROWS:
time.sleep(0.075)
elif state.nrows - 2 <= MAX_SPEED_ROWS:
vprint('no moves, speed up')
press_keys(win, 'l')
time.sleep(0.030)
else:
vprint('no moves')
solutions.append(solution)
buf.append(newstate)
except KeyboardInterrupt:
print('interrupted, quitting')
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment