Skip to content

Commit

Permalink
feat: implement finding hole heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
maiahi committed Apr 9, 2024
1 parent 5ca2103 commit 2001483
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/agents/heuristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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

0 comments on commit 2001483

Please sign in to comment.