Commit 409354ab authored by Taddeüs Kroes's avatar Taddeüs Kroes

Remove some unused code, format to PEP8

parent 213ebb76
......@@ -6,7 +6,7 @@ from itertools import count
from Xlib import error
from detection import NOBLOCK
from interaction import get_exapunks_window, focus_window, screenshot_board, \
press_keys, listen_keys, KEY_DELAY
press_keys, listen_keys
from strategy import State
......@@ -60,7 +60,7 @@ if __name__ == '__main__':
newstate = state.solve()
end = time.time()
vprint('thought for', round((end - start) * 1000, 1), 'ms')
except (TypeError, AssertionError) as e:
except (TypeError, AssertionError):
vprint('\rerror during parsing, wait for a bit...', end='')
time.sleep(0.050)
continue
......
......@@ -4,8 +4,7 @@ from collections import deque
from contextlib import redirect_stdout
from itertools import combinations, islice
from detection import COLUMNS, NOBLOCK, detect_blocks, detect_exa, \
detect_held, print_board, is_basic, is_bomb, \
bomb_to_basic
detect_held, print_board, is_basic, is_bomb
GRAB, DROP, SWAP, LEFT, RIGHT, SPEED = range(6)
......@@ -75,7 +74,8 @@ class State:
return cls(blocks, exa, held)
def copy(self):
return State(list(self.blocks), self.exa, self.held, list(self.colskip))
return self.__class__(list(self.blocks), self.exa, self.held,
list(self.colskip))
def causes_panic(self):
return self.max_colsize() >= COLSIZE_PANIC
......@@ -99,61 +99,9 @@ class State:
score += row - start_row + 1
return score
def score(self, points, moves, prev):
prev_colsize = prev.nrows - 2
#delay = moves_delay(moves)
delay = len(moves)
# Don't care about defragging for few rows, just score points quickly.
# This saves computation time which in turn makes for nice combos when
# the bot speeds around throwing blocks on top of each other.
if prev_colsize < DEFRAG_PRIO:
return -points, delay
holes = self.holes()
frag = 0 if points else self.fragmentation()
# When rows start stacking up, start defragmenting colors to make
# opportunities for scoring points.
if prev_colsize < COLSIZE_PRIO:
return -points, frag, holes, delay
# When they stack higher, start moving blocks down into holes before
# continuing to defragment.
if prev_colsize < COLSIZE_PANIC:
panic = int(self.causes_panic())
return panic, -points, holes, frag, delay
# Column heights are getting out of hand, just move shit DOWN.
return holes, delay, -points, frag
def find_unmovable_blocks(self):
unmoveable = set()
bombed = set()
for block, group in self.find_groups():
if is_basic(block) and len(group) >= MIN_BASIC_GROUP_SIZE:
for i in group:
unmoveable.add(i)
elif is_bomb(block) and len(group) >= MIN_BOMB_GROUP_SIZE:
bombed.add(bomb_to_basic(block))
for i in group:
unmoveable.add(i)
for i, block in enumerate(self.blocks):
if block in bombed:
unmoveable.add(i)
return unmoveable
def move(self, moves):
s = self.copy() if moves else self
s.moves = moves
# avoid swapping/grabbing currently exploding items
#unmoveable = s.find_unmovable_blocks()
s.placed = set()
s.grabbed = {}
......@@ -169,7 +117,6 @@ class State:
row = s.colskip[s.exa]
assert row < s.nrows
i = row * COLUMNS + s.exa
#assert i not in unmoveable
s.held = s.blocks[i]
s.blocks[i] = NOBLOCK
s.grabbed[i] = s.held
......@@ -188,8 +135,6 @@ class State:
i = row * COLUMNS + s.exa
j = i + COLUMNS
assert j < len(s.blocks)
#assert i not in unmoveable
#assert j not in unmoveable
bi = s.blocks[i]
bj = s.blocks[j]
if bi != bj:
......@@ -301,11 +246,6 @@ class State:
return -points
def has_explosion(self):
return any(is_bomb(block) and
any(self.blocks[j] == block for j in self.neighbors(i))
for i, block in enumerate(self.blocks))
def gen_moves(self):
yield ()
......@@ -378,7 +318,8 @@ class State:
return cls.holes, cls.nmoves, cls.points, cls.fragmentation
if colsize >= COLSIZE_PRIO:
return cls.causes_panic, cls.points, cls.holes, cls.fragmentation, cls.nmoves
return cls.causes_panic, cls.points, cls.holes, \
cls.fragmentation, cls.nmoves
return cls.points, cls.fragmentation, cls.holes, cls.nmoves
......@@ -446,7 +387,3 @@ if __name__ == '__main__':
print('target after move:')
newstate.print()
print()
#for solution in sorted(state.solutions()):
# print('move %18s:' % solution.keys(), solution.score)
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