Commit bc878146 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Cleanup

parent 8dcacb14
...@@ -12,7 +12,6 @@ MIN_COLUMN_SAT = 130 ...@@ -12,7 +12,6 @@ MIN_COLUMN_SAT = 130
MIN_COLUMN_VAL = 120 MIN_COLUMN_VAL = 120
COLUMN_VSHIFT = [1, 1, 1, 0, 0, 0, 0] COLUMN_VSHIFT = [1, 1, 1, 0, 0, 0, 0]
#COLUMN_VSHIFT = [2, 2, 1, 1, 0, 0, 0]
RED, PINK, GREEN, BLUE, YELLOW, NOBLOCK = range(6) RED, PINK, GREEN, BLUE, YELLOW, NOBLOCK = range(6)
BOMB_OFFSET = NOBLOCK + 1 BOMB_OFFSET = NOBLOCK + 1
......
...@@ -11,10 +11,10 @@ GET = ((GRAB,), (SWAP, GRAB), (GRAB, SWAP, DROP, SWAP, GRAB)) ...@@ -11,10 +11,10 @@ GET = ((GRAB,), (SWAP, GRAB), (GRAB, SWAP, DROP, SWAP, GRAB))
PUT = ((DROP,), (DROP, SWAP), (DROP, SWAP, GRAB, SWAP, DROP)) PUT = ((DROP,), (DROP, SWAP), (DROP, SWAP, GRAB, SWAP, DROP))
MIN_BASIC_GROUP_SIZE = 4 MIN_BASIC_GROUP_SIZE = 4
MIN_BOMB_GROUP_SIZE = 2 MIN_BOMB_GROUP_SIZE = 2
FIND_GROUPS_DEPTH = 4 FIND_GROUPS_DEPTH = 3
FRAG_DEPTH = 4 FRAG_DEPTH = 3
COLSIZE_PRIO = 5 COLSIZE_PRIO = 5
COLSIZE_PRIO_HIGH = 7 COLSIZE_PANIC = 7
COLSIZE_MAX = 8 COLSIZE_MAX = 8
BOMB_POINTS = 2 BOMB_POINTS = 2
MIN_ROWS = 2 MIN_ROWS = 2
...@@ -31,8 +31,6 @@ class State: ...@@ -31,8 +31,6 @@ class State:
skip = self.colskip(self.exa) skip = self.colskip(self.exa)
i = (skip + 1) * COLUMNS + self.exa i = (skip + 1) * COLUMNS + self.exa
return i < len(self.blocks) and self.blocks[i] == NOBLOCK return i < len(self.blocks) and self.blocks[i] == NOBLOCK
#return any(len(col) > 1 and col[1] == NOBLOCK
# for col in map(tuple, self.iter_columns()))
def iter_columns(self): def iter_columns(self):
nrows = self.nrows() nrows = self.nrows()
...@@ -60,11 +58,6 @@ class State: ...@@ -60,11 +58,6 @@ class State:
for col in range(COLUMNS): for col in range(COLUMNS):
yield self.nrows() - self.colskip(col) yield self.nrows() - self.colskip(col)
#def highest_column(self):
# for i, block in enumerate(self.blocks):
# if block != NOBLOCK:
# return self.nrows() - i // COLUMNS
def empty_column_score(self): def empty_column_score(self):
skip = 0 skip = 0
for i, block in enumerate(self.blocks): for i, block in enumerate(self.blocks):
...@@ -82,23 +75,13 @@ class State: ...@@ -82,23 +75,13 @@ class State:
return score return score
def score(self, points, moves, prev): def score(self, points, moves, prev):
#colsizes = list(self.colsizes())
#mincol = min(colsizes)
#maxcol = max(colsizes)
#colsize_score = maxcol, colsizes.count(maxcol) #, -mincol
#colsize_score = tuple(sorted(colsizes, reverse=True))
#if prev.nrows() >= 6:
# return colsize_score, -points, frag, len(moves)
#colsize_score = maxcol, self.empty_column_score()
frag = self.fragmentation() frag = self.fragmentation()
colsize_score = self.empty_column_score() colsize_score = self.empty_column_score()
#return -points, frag + colsize_score, len(moves) #return -points, frag + colsize_score, len(moves)
frag += colsize_score frag += colsize_score
prev_colsize = max(prev.colsizes()) prev_colsize = max(prev.colsizes())
if prev_colsize >= COLSIZE_PRIO_HIGH: if prev_colsize >= COLSIZE_PANIC:
return colsize_score, len(moves), -points, frag return colsize_score, len(moves), -points, frag
elif prev_colsize >= COLSIZE_PRIO: elif prev_colsize >= COLSIZE_PRIO:
return -points, colsize_score, frag, len(moves) return -points, colsize_score, frag, len(moves)
...@@ -106,10 +89,6 @@ class State: ...@@ -106,10 +89,6 @@ class State:
return -points, frag, colsize_score, len(moves) return -points, frag, colsize_score, len(moves)
def score_moves(self): def score_moves(self):
# clear exploding blocks before computing colsize
#prev = self.copy()
#prev.score_points()
for moves in self.gen_moves(): for moves in self.gen_moves():
try: try:
points, newstate = self.simulate(moves) points, newstate = self.simulate(moves)
...@@ -147,9 +126,6 @@ class State: ...@@ -147,9 +126,6 @@ class State:
s = self.copy() s = self.copy()
points = 0 points = 0
#if not moves:
# return s.score_points(), s
# avoid swapping/grabbing currently exploding items # avoid swapping/grabbing currently exploding items
#unmoveable = s.find_unmovable_blocks() #unmoveable = s.find_unmovable_blocks()
...@@ -228,15 +204,18 @@ class State: ...@@ -228,15 +204,18 @@ class State:
def fragmentation(self, depth=FRAG_DEPTH): def fragmentation(self, depth=FRAG_DEPTH):
""" """
Minimize the sum of dist(i,j) for all blocks i,j of the same color. Minimize the sum of dist(i,j) between all blocks i,j of the same color.
Prioritize horitontal distance to avoid column stacking. Magnify vertical distances to avoid column stacking.
""" """
def dist(i, j): def dist(i, j):
yi, xi = divmod(i, COLUMNS) yi, xi = divmod(i, COLUMNS)
yj, xj = divmod(j, COLUMNS) yj, xj = divmod(j, COLUMNS)
# for blocks in the same group, only count vertical distance so that
# groups are spread out horizontally
if groups[i] == groups[j]: if groups[i] == groups[j]:
return abs(yj - yi) return abs(yj - yi)
#return abs(xj - xi) * 2 + abs(yj - yi) - 1
return abs(xj - xi) + abs(yj - yi) * 2 - 1 return abs(xj - xi) + abs(yj - yi) * 2 - 1
colors = {} colors = {}
...@@ -345,7 +324,6 @@ def moves_to_keys(moves): ...@@ -345,7 +324,6 @@ def moves_to_keys(moves):
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
from PIL import Image from PIL import Image
#from pprint import pprint
board = Image.open('screens/board%d.png' % int(sys.argv[1])).convert('HSV') board = Image.open('screens/board%d.png' % int(sys.argv[1])).convert('HSV')
state = State.detect(board) state = State.detect(board)
...@@ -371,7 +349,3 @@ if __name__ == '__main__': ...@@ -371,7 +349,3 @@ if __name__ == '__main__':
for score, moves in sorted(state.score_moves()): for score, moves in sorted(state.score_moves()):
print('move %18s:' % moves_to_keys(moves), score) print('move %18s:' % moves_to_keys(moves), score)
#print('moves:', moves_to_keys(moves), moves)
#print('score:', score)
#print('\nmoves:', moves_to_keys(state.solve()))
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