|
@@ -13,11 +13,13 @@ MIN_BASIC_GROUP_SIZE = 4
|
|
|
MIN_BOMB_GROUP_SIZE = 2
|
|
MIN_BOMB_GROUP_SIZE = 2
|
|
|
FIND_GROUPS_DEPTH = 3
|
|
FIND_GROUPS_DEPTH = 3
|
|
|
FRAG_DEPTH = 3
|
|
FRAG_DEPTH = 3
|
|
|
|
|
+DEFRAG_PRIO = 3
|
|
|
COLSIZE_PRIO = 5
|
|
COLSIZE_PRIO = 5
|
|
|
COLSIZE_PANIC = 7
|
|
COLSIZE_PANIC = 7
|
|
|
COLSIZE_MAX = 8
|
|
COLSIZE_MAX = 8
|
|
|
-BOMB_POINTS = 2
|
|
|
|
|
|
|
+BOMB_POINTS = 1
|
|
|
MIN_ROWS = 2
|
|
MIN_ROWS = 2
|
|
|
|
|
+MAX_SPEED_ROWS = 3
|
|
|
|
|
|
|
|
|
|
|
|
|
class State:
|
|
class State:
|
|
@@ -58,6 +60,9 @@ 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 colsize_panic(self):
|
|
|
|
|
+ return int(max(self.colsizes()) >= COLSIZE_PANIC)
|
|
|
|
|
+
|
|
|
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):
|
|
@@ -75,18 +80,23 @@ class State:
|
|
|
return score
|
|
return score
|
|
|
|
|
|
|
|
def score(self, points, moves, prev):
|
|
def score(self, points, moves, prev):
|
|
|
- frag = self.fragmentation()
|
|
|
|
|
- colsize_score = self.empty_column_score()
|
|
|
|
|
- #return -points, frag + colsize_score, len(moves)
|
|
|
|
|
-
|
|
|
|
|
- frag += colsize_score
|
|
|
|
|
prev_colsize = max(prev.colsizes())
|
|
prev_colsize = max(prev.colsizes())
|
|
|
|
|
+ points = self.score_points()
|
|
|
|
|
+
|
|
|
if prev_colsize >= COLSIZE_PANIC:
|
|
if prev_colsize >= COLSIZE_PANIC:
|
|
|
- return colsize_score, len(moves), -points, frag
|
|
|
|
|
|
|
+ colsize = self.empty_column_score()
|
|
|
|
|
+ #frag = self.fragmentation()
|
|
|
|
|
+ return colsize, len(moves), -points #, frag
|
|
|
|
|
+ elif prev_colsize >= DEFRAG_PRIO:
|
|
|
|
|
+ colsize = self.empty_column_score()
|
|
|
|
|
+ frag = self.fragmentation()
|
|
|
|
|
+ panic = self.colsize_panic()
|
|
|
|
|
+ return -points, panic, frag, colsize, len(moves)
|
|
|
elif prev_colsize >= COLSIZE_PRIO:
|
|
elif prev_colsize >= COLSIZE_PRIO:
|
|
|
- return -points, colsize_score, frag, len(moves)
|
|
|
|
|
|
|
+ colsize = self.empty_column_score()
|
|
|
|
|
+ return -points, colsize, len(moves)
|
|
|
else:
|
|
else:
|
|
|
- return -points, frag, colsize_score, len(moves)
|
|
|
|
|
|
|
+ return -points, len(moves)
|
|
|
|
|
|
|
|
def score_moves(self):
|
|
def score_moves(self):
|
|
|
for moves in self.gen_moves():
|
|
for moves in self.gen_moves():
|
|
@@ -165,7 +175,6 @@ class State:
|
|
|
if moves and max(self.colsizes()) < COLSIZE_MAX:
|
|
if moves and max(self.colsizes()) < COLSIZE_MAX:
|
|
|
assert max(s.colsizes()) <= COLSIZE_MAX
|
|
assert max(s.colsizes()) <= COLSIZE_MAX
|
|
|
|
|
|
|
|
- points += s.score_points()
|
|
|
|
|
return points, s
|
|
return points, s
|
|
|
|
|
|
|
|
def find_groups(self, depth=FIND_GROUPS_DEPTH, minsize=2):
|
|
def find_groups(self, depth=FIND_GROUPS_DEPTH, minsize=2):
|
|
@@ -233,31 +242,31 @@ class State:
|
|
|
for i, j in combinations(color, 2))
|
|
for i, j in combinations(color, 2))
|
|
|
|
|
|
|
|
def score_points(self, multiplier=1):
|
|
def score_points(self, multiplier=1):
|
|
|
- remove = []
|
|
|
|
|
|
|
+ #remove = []
|
|
|
points = 0
|
|
points = 0
|
|
|
|
|
|
|
|
for block, group in self.find_groups():
|
|
for block, group in self.find_groups():
|
|
|
if is_basic(block) and len(group) >= MIN_BASIC_GROUP_SIZE:
|
|
if is_basic(block) and len(group) >= MIN_BASIC_GROUP_SIZE:
|
|
|
- remove.extend(group)
|
|
|
|
|
|
|
+ #remove.extend(group)
|
|
|
points += len(group) * multiplier
|
|
points += len(group) * multiplier
|
|
|
elif is_bomb(block) and len(group) >= MIN_BOMB_GROUP_SIZE:
|
|
elif is_bomb(block) and len(group) >= MIN_BOMB_GROUP_SIZE:
|
|
|
points += BOMB_POINTS
|
|
points += BOMB_POINTS
|
|
|
- remove.extend(group)
|
|
|
|
|
- for i, other in enumerate(self.blocks):
|
|
|
|
|
- if other == bomb_to_basic(block):
|
|
|
|
|
- remove.append(i)
|
|
|
|
|
-
|
|
|
|
|
- remove.sort()
|
|
|
|
|
- prev = None
|
|
|
|
|
- for i in remove:
|
|
|
|
|
- if i != prev:
|
|
|
|
|
- while self.blocks[i] != NOBLOCK:
|
|
|
|
|
- self.blocks[i] = self.blocks[i - COLUMNS]
|
|
|
|
|
- i -= COLUMNS
|
|
|
|
|
- prev = i
|
|
|
|
|
-
|
|
|
|
|
- if points:
|
|
|
|
|
- points += self.score_points(min(2, multiplier * 2))
|
|
|
|
|
|
|
+ #remove.extend(group)
|
|
|
|
|
+ #for i, other in enumerate(self.blocks):
|
|
|
|
|
+ # if other == bomb_to_basic(block):
|
|
|
|
|
+ # remove.append(i)
|
|
|
|
|
+
|
|
|
|
|
+ #remove.sort()
|
|
|
|
|
+ #prev = None
|
|
|
|
|
+ #for i in remove:
|
|
|
|
|
+ # if i != prev:
|
|
|
|
|
+ # while self.blocks[i] != NOBLOCK:
|
|
|
|
|
+ # self.blocks[i] = self.blocks[i - COLUMNS]
|
|
|
|
|
+ # i -= COLUMNS
|
|
|
|
|
+ # prev = i
|
|
|
|
|
+
|
|
|
|
|
+ #if points:
|
|
|
|
|
+ # points += self.score_points(min(2, multiplier * 2))
|
|
|
return points
|
|
return points
|
|
|
|
|
|
|
|
def has_explosion(self):
|
|
def has_explosion(self):
|
|
@@ -299,7 +308,7 @@ class State:
|
|
|
return ()
|
|
return ()
|
|
|
|
|
|
|
|
score, moves = min(self.score_moves())
|
|
score, moves = min(self.score_moves())
|
|
|
- if not moves:
|
|
|
|
|
|
|
+ if not moves and max(self.colsizes()) <= MAX_SPEED_ROWS:
|
|
|
return (SPEED,)
|
|
return (SPEED,)
|
|
|
return moves
|
|
return moves
|
|
|
|
|
|