From 774ea6cb0ebd1f1f98898d580bbea23ea1763ffe Mon Sep 17 00:00:00 2001 From: Eduard Prokhorikhin Date: Mon, 8 Apr 2024 19:34:08 +0200 Subject: [PATCH] feat: added the first heuristic --- src/agents/heuristic.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/agents/heuristic.py b/src/agents/heuristic.py index 3f3dec2..22b8b43 100644 --- a/src/agents/heuristic.py +++ b/src/agents/heuristic.py @@ -9,4 +9,29 @@ def utility(gameState: Board) -> int: def aggregate_heights(gameState: Board) -> int: """ Returns the sum of the heights of the columns in the game state. """ - pass + checkedList = [0 for i in range(gameState.columns)] + for i in range(gameState.rows): + for j in range(gameState.columns): + if gameState.board[i][j] > 0: + if checkedList[j] == 0: + checkedList[j] = gameState.rows - i+1 + return sum(checkedList) + + + + +if __name__ == "__main__": + board = Board() + board.board =\ + [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 1, 0, 1, 0, 0, 0, 0, 0, 0], + [1, 0, 0, 0, 0, 0, 1, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] + + assert aggregate_heights(board) == 27 \ No newline at end of file