From e9f7b2d59db29b459e9548f723160e6f42d73777 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Sat, 13 Jan 2024 20:05:12 +0200 Subject: [PATCH] fix(ai): `count_holes` --- src/ai/heuristics/holes.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ai/heuristics/holes.py b/src/ai/heuristics/holes.py index 50bf441..f12ef30 100644 --- a/src/ai/heuristics/holes.py +++ b/src/ai/heuristics/holes.py @@ -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