fix(ai): count_holes

This commit is contained in:
Kristofers Solo 2024-01-13 20:05:12 +02:00
parent d458a56d27
commit e9f7b2d59d

View File

@ -15,8 +15,15 @@ def count_holes(
The total number of holes in the field.
"""
first_nonzero_indices = np.argmax(field != 0, axis=0)
num_rows, num_cols = field.shape
holes_count = 0
mask = (field == 0) & (np.arange(field.shape[0])[:, np.newaxis] > first_nonzero_indices)
for col in range(num_cols):
has_tile_above = False
return int(np.sum(mask))
for row in range(num_rows):
if field[row, col] == 1:
has_tile_above = True
elif field[row, col] == 0 and has_tile_above:
holes_count += 1
return holes_count