From 20014835b05d3519af84bc07856546f24fbe988f Mon Sep 17 00:00:00 2001 From: Maia Austigard Date: Tue, 9 Apr 2024 18:50:28 +0200 Subject: [PATCH] feat: implement finding hole heuristic --- src/agents/heuristic.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/agents/heuristic.py b/src/agents/heuristic.py index 88080ef..00ff125 100644 --- a/src/agents/heuristic.py +++ b/src/agents/heuristic.py @@ -25,4 +25,24 @@ def max_height(gameState: Board) -> int: if gameState.board[i][j] > 0: if checkedList[j] == 0: checkedList[j] = gameState.rows - i - return max(checkedList) \ No newline at end of file + return max(checkedList) + +def find_holes(gameState: Board) -> int: + """ Returns number of empty cells on the board. + + Args: + gameState (Board): the state to check + + Returns: + The heuristic value + """ + holes = 0 + for i in range(gameState.columns): + top_block = 20 + for j in range(gameState.rows): + if (gameState.board[j][i] == 1) and (j < top_block): + top_block = j + if (gameState.board[j][i] == 0) and (j > top_block): + holes += 1 + + return holes \ No newline at end of file