exp per player now resets for each episode
|
@ -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():
|
||||
|
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 16 KiB |
5
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)
|
||||
|
|
23
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,10 +223,6 @@ if __name__ == "__main__":
|
|||
|
||||
print(f"Models saved to {chkpt_path}")
|
||||
|
||||
# End of training session
|
||||
print("End of episodes.\
|
||||
\nExiting game...")
|
||||
|
||||
plt.figure()
|
||||
plt.title("Player Performance")
|
||||
plt.xlabel("Episode")
|
||||
|
@ -232,6 +231,7 @@ if __name__ == "__main__":
|
|||
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")
|
||||
|
@ -241,6 +241,7 @@ if __name__ == "__main__":
|
|||
for actor in actor_loss:
|
||||
plt.plot(actor)
|
||||
plt.savefig(f"{figure_folder}/actor_loss.png")
|
||||
plt.close()
|
||||
|
||||
plt.figure()
|
||||
plt.suptitle("Critic Loss")
|
||||
|
@ -250,6 +251,7 @@ if __name__ == "__main__":
|
|||
for critic in critic_loss:
|
||||
plt.plot(critic)
|
||||
plt.savefig(f"{figure_folder}/critic_loss.png")
|
||||
plt.close()
|
||||
|
||||
plt.figure()
|
||||
plt.suptitle("Total Loss")
|
||||
|
@ -259,5 +261,10 @@ if __name__ == "__main__":
|
|||
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...")
|
||||
|
||||
game.quit()
|
||||
|
|