From 01a84bc2011a2768b1c206167a2aa394b7e36bf8 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Fri, 5 Jan 2024 18:40:00 +0200 Subject: [PATCH] feat(ai): add `get_holes_sum` --- src/ai/fitness/holes.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ai/fitness/holes.py b/src/ai/fitness/holes.py index 5c8b110..b647d99 100644 --- a/src/ai/fitness/holes.py +++ b/src/ai/fitness/holes.py @@ -20,3 +20,14 @@ def get_holes( holes[col] = np.count_nonzero(field[int(start) :, col] == 0) return holes + + +def get_holes_sum( + *, holes: Optional[np.ndarray] = None, field: Optional[np.ndarray] = None +) -> int: + if holes is None and field is None: + raise ValueError("holes and field cannot both be None") + elif holes is None: + holes = get_holes(field) + + return int(np.sum(holes))