Skip to content

Commit

Permalink
feat: added the first heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard-Prokhorikhin committed Apr 8, 2024
1 parent 407c3fd commit 774ea6c
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/agents/heuristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 774ea6c

Please sign in to comment.