Commit 47fcb032 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Skip simulated moves that try to move exploding blocks

parent 0bb45a59
...@@ -92,6 +92,15 @@ class State: ...@@ -92,6 +92,15 @@ class State:
score += row - start_row + 1 score += row - start_row + 1
return score return score
def locked(self, i):
block = self.blocks[i]
if block == NOBLOCK:
return False
if is_basic(block):
return self.groupsizes[i] >= MIN_BASIC_GROUP_SIZE
assert is_bomb(block)
return self.groupsizes[i] >= MIN_BOMB_GROUP_SIZE
def move(self, *moves): def move(self, *moves):
deep = any(move in (GRAB, DROP, SWAP) for move in moves) deep = any(move in (GRAB, DROP, SWAP) for move in moves)
s = self.copy(deep) s = self.copy(deep)
...@@ -112,39 +121,39 @@ class State: ...@@ -112,39 +121,39 @@ class State:
row = s.colskip[s.exa] row = s.colskip[s.exa]
assert row < s.nrows assert row < s.nrows
i = row * COLUMNS + s.exa i = row * COLUMNS + s.exa
s.held = s.blocks[i] if not s.locked(i):
s.blocks[i] = NOBLOCK s.held = s.blocks[i]
s.colskip[s.exa] += 1 s.blocks[i] = NOBLOCK
s.ungroup(i) s.colskip[s.exa] += 1
s.ungroup(i)
elif move == DROP: elif move == DROP:
assert not s.colbusy(s.exa) if s.held != NOBLOCK:
assert s.held != NOBLOCK row = s.colskip[s.exa]
row = s.colskip[s.exa] assert row > 0
assert row > 0 i = (row - 1) * COLUMNS + s.exa
i = (row - 1) * COLUMNS + s.exa s.blocks[i] = s.held
s.blocks[i] = s.held s.held = NOBLOCK
s.held = NOBLOCK s.colskip[s.exa] -= 1
s.colskip[s.exa] -= 1 s.regroup(i)
s.regroup(i)
elif move == SWAP: elif move == SWAP:
assert not s.colbusy(s.exa) assert not s.colbusy(s.exa)
row = s.colskip[s.exa] row = s.colskip[s.exa]
i = row * COLUMNS + s.exa i = row * COLUMNS + s.exa
j = i + COLUMNS j = i + COLUMNS
assert j < len(s.blocks) if j < len(s.blocks) and not s.locked(i) and not s.locked(j):
bi = s.blocks[i] bi = s.blocks[i]
bj = s.blocks[j] bj = s.blocks[j]
if bi != bj: if bi != bj:
s.blocks[i] = NOBLOCK s.blocks[i] = NOBLOCK
s.blocks[j] = NOBLOCK s.blocks[j] = NOBLOCK
s.ungroup(i) s.ungroup(i)
s.ungroup(j) s.ungroup(j)
s.blocks[j] = bi s.blocks[j] = bi
s.regroup(j) s.regroup(j)
s.blocks[i] = bj s.blocks[i] = bj
s.regroup(i) s.regroup(i)
return s return s
......
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