Updated rewards and fixed formatting

This commit is contained in:
Vasilis Valatsos 2024-03-07 10:27:26 +02:00
parent e57d826239
commit 32bff8b5c5
3 changed files with 4 additions and 8 deletions

View file

@ -161,7 +161,7 @@ class Player(pygame.sprite.Sprite):
self.old_state_features = self.state_features self.old_state_features = self.state_features
self.reward = self.stats.exp self.reward = self.stats.exp
# + self.stats.health/self.stats.stats['health'] - 1\ + self.stats.health/self.stats.stats['health'] - 1
# - nearest_dist/np.sqrt(np.sum(self.map_edge)) # - nearest_dist/np.sqrt(np.sum(self.map_edge))
self.state_features = [ self.state_features = [

View file

@ -294,7 +294,6 @@ class Level:
if player.is_dead(): if player.is_dead():
print(f"\nPlayer {player.player_id} is dead\n") print(f"\nPlayer {player.player_id} is dead\n")
player.stats.exp = -10 player.stats.exp = -10
player.update()
self.dead_players[player.player_id] = player.is_dead() self.dead_players[player.player_id] = player.is_dead()
self.done = True if (self.dead_players.all() == 1 self.done = True if (self.dead_players.all() == 1

View file

@ -26,6 +26,7 @@ def main():
chkpt_path, figure_path = folder_struct.setup_dirs() chkpt_path, figure_path = folder_struct.setup_dirs()
# Setup AI params
n_episodes = parsed_args.n_episodes n_episodes = parsed_args.n_episodes
episode_length = parsed_args.ep_length episode_length = parsed_args.ep_length
n_agents = parsed_args.n_agents n_agents = parsed_args.n_agents
@ -38,8 +39,6 @@ def main():
show_pygame = parsed_args.show_pg show_pygame = parsed_args.show_pg
# Setup AI metrics
# Setup parameter monitoring # Setup parameter monitoring
score_history = np.zeros( score_history = np.zeros(
shape=(parsed_args.n_agents, parsed_args.n_episodes)) shape=(parsed_args.n_agents, parsed_args.n_episodes))
@ -63,9 +62,6 @@ def main():
time_alive = np.zeros(shape=(parsed_args.n_agents, time_alive = np.zeros(shape=(parsed_args.n_agents,
parsed_args.n_episodes)) parsed_args.n_episodes))
# score_history, best_score, actor_loss, critic_loss, total_loss, entropy, advantage = metrics.generate(parsed_args)
game = Pneuma(show_pg=show_pygame, n_players=parsed_args.n_agents) game = Pneuma(show_pg=show_pygame, n_players=parsed_args.n_agents)
print("Initializing agents ...") print("Initializing agents ...")
@ -202,9 +198,10 @@ def main():
metrics.plot_parameter('advantage', advantage, parsed_args.n_agents, figure_path) metrics.plot_parameter('advantage', advantage, parsed_args.n_agents, figure_path)
metrics.plot_avg_time(time_alive, parsed_args.n_agents, figure_path) metrics.plot_avg_time(time_alive, parsed_args.n_agents, figure_path)
# End of training session # End of training session
print("End of episodes.\ print("End of episodes.\
\nExiting game...") \n Saving models and exiting game...")
# Save models # Save models
player.agent.save_models( player.agent.save_models(