fix(ai): get_bumpiness

This commit is contained in:
Kristofers Solo 2024-01-13 19:49:39 +02:00
parent e84cacca1c
commit d458a56d27
2 changed files with 7 additions and 3 deletions

View File

@ -1,11 +1,13 @@
import numpy as np import numpy as np
from .peaks import get_peaks
def get_bumpiness( def get_bumpiness(
field: np.ndarray[int, np.dtype[np.uint8]], field: np.ndarray[int, np.dtype[np.uint8]],
) -> int: ) -> int:
""" """
Calculate the bumpiness of a given signal based on peaks. Calculate the bumpiness of a given field based on peaks.
Args: Args:
field: The game field. field: The game field.
@ -13,4 +15,6 @@ def get_bumpiness(
Returns: Returns:
The bumpiness of the field. The bumpiness of the field.
""" """
return int(np.sum(np.abs(np.diff(field.shape[0] - np.argmax(field, axis=0))))) field = get_peaks(field)
diff = np.diff(field)
return int(np.sum(np.abs(diff)))

View File

@ -11,7 +11,7 @@ def get_peaks(field: np.ndarray[int, np.dtype[np.uint8]]) -> np.ndarray[int, np.
Returns: Returns:
2D array representing the peaks of the field. 2D array representing the peaks of the field.
""" """
result = np.zeros(field.shape[1], dtype=np.uint8) result = np.zeros(field.shape[1], dtype=int)
for col in range(field.shape[1]): for col in range(field.shape[1]):
for row in range(field.shape[0]): for row in range(field.shape[0]):
if field[row, col] != 0: if field[row, col] != 0: