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