Skip to content

Commit

Permalink
feat: 🚀 genetic agent class and it's training algorithm commenced
Browse files Browse the repository at this point in the history
  • Loading branch information
oystkva committed Apr 29, 2024
1 parent f687c53 commit 98b33b4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test():

# # manager.startGame()

<<<<<<< HEAD
# # train()


Expand All @@ -52,3 +53,7 @@ def test():


# cProfile.run('main()', 'restats')
=======
#train()

>>>>>>> c14418b (feat: :rocket: genetic agent class and it's training algorithm commenced)
5 changes: 5 additions & 0 deletions src/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def play_game(agent: Agent, board: Tetris, actions_per_drop: int = 1, max_pieces
Returns:
The final state of the board after the game is over.
"""
<<<<<<< HEAD
<<<<<<< HEAD
#count = 0

Expand All @@ -55,6 +56,10 @@ def play_game(agent: Agent, board: Tetris, actions_per_drop: int = 1, max_pieces
pieces_dropped = 0
while not board.isGameOver() and pieces_dropped < max_pieces_dropped:
>>>>>>> b842fc6 (feat: :rocket: genetic agent class and it's training algorithm commenced)
=======
pieces_dropped = 0
while not board.isGameOver() and pieces_dropped < max_pieces_dropped:
>>>>>>> c14418b (feat: :rocket: genetic agent class and it's training algorithm commenced)
# Get the result of the agent's action
for _ in range(actions_per_drop):
result = agent.result(board)
Expand Down
4 changes: 4 additions & 0 deletions src/agents/heuristic.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ def max_height(gameState: Tetris) -> int:
return max(checkedList)


<<<<<<< HEAD
# Does this work? row cleared in get_possible_boards??
def lines_cleaned(gameState: Tetris) -> int:
=======
def lines_cleared(gameState: Tetris) -> int:
>>>>>>> c14418b (feat: :rocket: genetic agent class and it's training algorithm commenced)
"""Retrurns the number of lines cleared."""
sum = 0
for row in gameState.board:
Expand Down
10 changes: 10 additions & 0 deletions src/agents/heuristic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ def result(self, board: Tetris) -> list[Action]:

# Find the actions needed to transform the current board to the new board
actions = []
<<<<<<< HEAD
actions = transition_model(board, best_board)
return actions

=======
try:
actions = transition_model(board, best_board)
return actions
except:
return actions


>>>>>>> c14418b (feat: :rocket: genetic agent class and it's training algorithm commenced)

0 comments on commit 98b33b4

Please sign in to comment.