|
@@ -24,6 +24,9 @@ def save_screenshot(win):
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
|
|
+ import sys
|
|
|
|
|
+ verbose = '-q' not in sys.argv[1:]
|
|
|
|
|
+
|
|
|
try:
|
|
try:
|
|
|
win = get_exapunks_window()
|
|
win = get_exapunks_window()
|
|
|
focus_window(win)
|
|
focus_window(win)
|
|
@@ -32,54 +35,61 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
solutions = deque([], maxlen=3)
|
|
solutions = deque([], maxlen=3)
|
|
|
|
|
|
|
|
|
|
+ def vprint(*args, **kwargs):
|
|
|
|
|
+ if verbose:
|
|
|
|
|
+ print(*args, **kwargs)
|
|
|
|
|
+
|
|
|
|
|
+ def vprint_state(state):
|
|
|
|
|
+ if verbose:
|
|
|
|
|
+ state.print()
|
|
|
|
|
+
|
|
|
while True:
|
|
while True:
|
|
|
try:
|
|
try:
|
|
|
board = screenshot_board(win)
|
|
board = screenshot_board(win)
|
|
|
|
|
|
|
|
state = State.detect(board)
|
|
state = State.detect(board)
|
|
|
- print('\033c', end='')
|
|
|
|
|
- print('parsed:')
|
|
|
|
|
- state.print()
|
|
|
|
|
- print()
|
|
|
|
|
|
|
+ vprint('\033c', 'parsed:', sep='')
|
|
|
|
|
+ vprint_state(state)
|
|
|
|
|
+ vprint()
|
|
|
|
|
|
|
|
start = time.time()
|
|
start = time.time()
|
|
|
solution = state.solve()
|
|
solution = state.solve()
|
|
|
end = time.time()
|
|
end = time.time()
|
|
|
- print('thought for', round((end - start) * 1000, 1), 'milliseconds')
|
|
|
|
|
|
|
+ vprint('thought for', round((end - start) * 1000, 1), 'milliseconds')
|
|
|
except (TypeError, AssertionError):
|
|
except (TypeError, AssertionError):
|
|
|
- print('\rerror during parsing, wait for a bit...', end='')
|
|
|
|
|
- time.sleep(0.05)
|
|
|
|
|
|
|
+ vprint('\rerror during parsing, wait for a bit...', end='')
|
|
|
|
|
+ time.sleep(0.050)
|
|
|
continue
|
|
continue
|
|
|
except error.BadMatch:
|
|
except error.BadMatch:
|
|
|
- print('\rEXAPUNKS window lost, wait for a bit...', end='')
|
|
|
|
|
- time.sleep(0.5)
|
|
|
|
|
|
|
+ vprint('\rEXAPUNKS window lost, wait for a bit...', end='')
|
|
|
|
|
+ time.sleep(0.500)
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
if len(solutions) == 3 and solution.loops(solutions.popleft()):
|
|
if len(solutions) == 3 and solution.loops(solutions.popleft()):
|
|
|
- print('\rloop detected, wait for a bit...', end='')
|
|
|
|
|
|
|
+ vprint('\rloop detected, wait for a bit...', end='')
|
|
|
time.sleep(0.03)
|
|
time.sleep(0.03)
|
|
|
elif solution.moves:
|
|
elif solution.moves:
|
|
|
- print('moves:', solution.keys())
|
|
|
|
|
- print(' score:', solution.score)
|
|
|
|
|
|
|
+ vprint('moves:', solution.keys())
|
|
|
|
|
+ vprint(' score:', solution.score)
|
|
|
if solutions:
|
|
if solutions:
|
|
|
- print('prev score:', solutions[-1].score)
|
|
|
|
|
- print()
|
|
|
|
|
|
|
+ vprint('prev score:', solutions[-1].score)
|
|
|
|
|
+ vprint()
|
|
|
|
|
|
|
|
- print('target after moves:')
|
|
|
|
|
- solution.newstate.print()
|
|
|
|
|
|
|
+ vprint('target after moves:')
|
|
|
|
|
+ vprint_state(solution.newstate)
|
|
|
|
|
|
|
|
press_keys(win, solution.keys())
|
|
press_keys(win, solution.keys())
|
|
|
|
|
|
|
|
keys_delay = len(solution.moves) * 2 * KEY_DELAY
|
|
keys_delay = len(solution.moves) * 2 * KEY_DELAY
|
|
|
moves_delay = max(0, solution.delay() - keys_delay)
|
|
moves_delay = max(0, solution.delay() - keys_delay)
|
|
|
- print('wait for', moves_delay, 'ms')
|
|
|
|
|
|
|
+ vprint('wait for', moves_delay, 'ms')
|
|
|
time.sleep(moves_delay / 1000)
|
|
time.sleep(moves_delay / 1000)
|
|
|
elif state.nrows() - 2 <= MAX_SPEED_ROWS:
|
|
elif state.nrows() - 2 <= MAX_SPEED_ROWS:
|
|
|
- print('no moves, speed up')
|
|
|
|
|
|
|
+ vprint('no moves, speed up')
|
|
|
press_keys(win, 'l')
|
|
press_keys(win, 'l')
|
|
|
- time.sleep(0.03)
|
|
|
|
|
|
|
+ time.sleep(0.030)
|
|
|
else:
|
|
else:
|
|
|
- print('no moves')
|
|
|
|
|
|
|
+ vprint('no moves')
|
|
|
|
|
|
|
|
solutions.append(solution)
|
|
solutions.append(solution)
|
|
|
except KeyboardInterrupt:
|
|
except KeyboardInterrupt:
|