Skip to content

Commit

Permalink
feat: create play_game to make agent play games from start to end
Browse files Browse the repository at this point in the history
  • Loading branch information
SverreNystad committed Apr 9, 2024
1 parent 24cbd10 commit b6d4826
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,26 @@ def result(board: Board) -> Union[Action, list[Action]]:
"""
pass


def play_game(agent: Agent, board: Board) -> Board:
"""
Plays a game of Tetris with the given agent.
Args:
agent (Agent): The agent to play the game.
board (Board): The initial state of the board.
Returns:
The final state of the board after the game is over.
"""
while not board.isGameOver():
result = agent.result(board)
print(f"[Agent] Move: {result}")
if isinstance(result, list):
for action in result:
board.doAction(action)
else:
board.doAction(result)

board.printBoard()
return board

0 comments on commit b6d4826

Please sign in to comment.