diff --git a/agents/saved_models/A0 b/agents/saved_models/A0 index d1dbc28..c18b620 100644 Binary files a/agents/saved_models/A0 and b/agents/saved_models/A0 differ diff --git a/agents/saved_models/C0 b/agents/saved_models/C0 index 42f68bb..f5e8857 100644 Binary files a/agents/saved_models/C0 and b/agents/saved_models/C0 differ diff --git a/entities/player.py b/entities/player.py index 60f8df8..fa4c168 100644 --- a/entities/player.py +++ b/entities/player.py @@ -231,6 +231,8 @@ class Player(pygame.sprite.Sprite): self.get_current_state() + print(self.reward_features) + def update(self): if not self.is_dead(): diff --git a/figures/actor_loss.png b/figures/actor_loss.png index afce6b8..59145da 100644 Binary files a/figures/actor_loss.png and b/figures/actor_loss.png differ diff --git a/figures/critic_loss.png b/figures/critic_loss.png index 7e11664..ce24bf2 100644 Binary files a/figures/critic_loss.png and b/figures/critic_loss.png differ diff --git a/figures/score.png b/figures/score.png index a235e71..20c1a7b 100644 Binary files a/figures/score.png and b/figures/score.png differ diff --git a/figures/total_loss.png b/figures/total_loss.png index 8ade31a..50854b0 100644 Binary files a/figures/total_loss.png and b/figures/total_loss.png differ diff --git a/level.py b/level.py index ba30cef..3893d31 100644 --- a/level.py +++ b/level.py @@ -205,13 +205,18 @@ class Level: self.obstacle_sprites) for player in self.player_sprites: + player.animation.import_assets( choice(self.possible_player_locations)) + player.stats.health\ = player.stats.stats['health'] + player.stats.energy\ = player.stats.stats['energy'] + player.stats.exp = 0 + self.get_entities() self.get_distance_direction() self.dead_players = np.zeros(self.n_players) diff --git a/pneuma.py b/pneuma.py index 2a30b64..69b22bf 100644 --- a/pneuma.py +++ b/pneuma.py @@ -189,8 +189,11 @@ if __name__ == "__main__": # Gather information about the episode for player in game.level.player_sprites: + score = np.mean(player.reward_features) + print(player.reward_features) + # Update score - score_history[player.player_id][episode] = player.stats.exp + score_history[player.player_id][episode] = np.mean(score) # Update actor/critic loss actor_loss[player.player_id][episode] = np.mean( @@ -203,13 +206,13 @@ if __name__ == "__main__": episode_total_loss) # Check for new best score - if player.stats.exp > best_score[player.player_id]: + if score > best_score[player.player_id]: print(f"\nNew best score for player {player.player_id}:\ - {player.stats.exp}\ + {score}\ \nOld best score for player {player.player_id}: \ {best_score[player.player_id]}") - best_score[player.player_id] = player.stats.exp + best_score[player.player_id] = score print(f"Saving models for player {player.player_id}...") @@ -220,44 +223,48 @@ if __name__ == "__main__": print(f"Models saved to {chkpt_path}") + plt.figure() + plt.title("Player Performance") + plt.xlabel("Episode") + plt.ylabel("Score") + plt.legend([f"Player {num}" for num in range(n_players)]) + for player_score in score_history: + plt.plot(player_score) + plt.savefig(f"{figure_folder}/score.png") + plt.close() + + plt.figure() + plt.suptitle("Actor Loss") + plt.xlabel("Episode") + plt.ylabel("Loss") + plt.legend([f"Agent {num}" for num in range(n_players)]) + for actor in actor_loss: + plt.plot(actor) + plt.savefig(f"{figure_folder}/actor_loss.png") + plt.close() + + plt.figure() + plt.suptitle("Critic Loss") + plt.xlabel("Episode") + plt.ylabel("Loss") + plt.legend([f"Agent {num}" for num in range(n_players)]) + for critic in critic_loss: + plt.plot(critic) + plt.savefig(f"{figure_folder}/critic_loss.png") + plt.close() + + plt.figure() + plt.suptitle("Total Loss") + plt.xlabel("Episode") + plt.ylabel("Loss") + plt.legend([f"Agent {num}" for num in range(n_players)]) + for total in total_loss: + plt.plot(total) + plt.savefig(f"{figure_folder}/total_loss.png") + plt.close() + # End of training session print("End of episodes.\ \nExiting game...") - plt.figure() - plt.title("Player Performance") - plt.xlabel("Episode") - plt.ylabel("Score") - plt.legend([f"Player {num}" for num in range(n_players)]) - for player_score in score_history: - plt.plot(player_score) - plt.savefig(f"{figure_folder}/score.png") - - plt.figure() - plt.suptitle("Actor Loss") - plt.xlabel("Episode") - plt.ylabel("Loss") - plt.legend([f"Agent {num}" for num in range(n_players)]) - for actor in actor_loss: - plt.plot(actor) - plt.savefig(f"{figure_folder}/actor_loss.png") - - plt.figure() - plt.suptitle("Critic Loss") - plt.xlabel("Episode") - plt.ylabel("Loss") - plt.legend([f"Agent {num}" for num in range(n_players)]) - for critic in critic_loss: - plt.plot(critic) - plt.savefig(f"{figure_folder}/critic_loss.png") - - plt.figure() - plt.suptitle("Total Loss") - plt.xlabel("Episode") - plt.ylabel("Loss") - plt.legend([f"Agent {num}" for num in range(n_players)]) - for total in total_loss: - plt.plot(total) - plt.savefig(f"{figure_folder}/total_loss.png") - game.quit()