diff --git a/agents/saved_models/A0 b/agents/saved_models/A0 index e2e5a71..10fba3e 100644 Binary files a/agents/saved_models/A0 and b/agents/saved_models/A0 differ diff --git a/agents/saved_models/A1 b/agents/saved_models/A1 new file mode 100644 index 0000000..eb35b63 Binary files /dev/null and b/agents/saved_models/A1 differ diff --git a/agents/saved_models/C0 b/agents/saved_models/C0 index 56aba3a..d04935b 100644 Binary files a/agents/saved_models/C0 and b/agents/saved_models/C0 differ diff --git a/agents/saved_models/C1 b/agents/saved_models/C1 new file mode 100644 index 0000000..17bd2a1 Binary files /dev/null and b/agents/saved_models/C1 differ diff --git a/effects/magic_effects.py b/effects/magic_effects.py index 2443715..5ffe55e 100644 --- a/effects/magic_effects.py +++ b/effects/magic_effects.py @@ -17,12 +17,12 @@ class MagicPlayer: player.stats.health = player.stats.stats['health'] self.animation_player.generate_particles( 'aura', - player.rect.center, + player.animation.rect.center, groups) self.animation_player.generate_particles( 'heal', - player.rect.center + pygame.math.Vector2(0, -50), + player.animation.rect.center + pygame.math.Vector2(0, -50), groups) def flame(self, player, cost, groups): @@ -41,17 +41,17 @@ class MagicPlayer: for i in range(1, 6): if direction.x: offset_x = direction.x * i * TILESIZE - x = player.rect.centerx + offset_x + \ + x = player.animation.rect.centerx + offset_x + \ randint(-TILESIZE // 3, TILESIZE // 3) - y = player.rect.centery + \ + y = player.animation.rect.centery + \ randint(-TILESIZE // 3, TILESIZE // 3) self.animation_player.generate_particles( 'flame', (x, y), groups) else: offset_y = direction.y * i * TILESIZE - x = player.rect.centerx + \ + x = player.animation.rect.centerx + \ randint(-TILESIZE // 3, TILESIZE // 3) - y = player.rect.centery + offset_y + \ + y = player.animation.rect.centery + offset_y + \ randint(-TILESIZE // 3, TILESIZE // 3) self.animation_player.generate_particles( 'flame', (x, y), groups) diff --git a/effects/weapon_effects.py b/effects/weapon_effects.py index 2eada75..4cc4f52 100644 --- a/effects/weapon_effects.py +++ b/effects/weapon_effects.py @@ -23,13 +23,13 @@ class Weapon(pygame.sprite.Sprite): # Sprite Placement if direction == 'right': self.rect = self.image.get_rect( - midleft=player.rect.midright + pygame.math.Vector2(0, 16)) + midleft=player.animation.rect.midright + pygame.math.Vector2(0, 16)) elif direction == 'left': self.rect = self.image.get_rect( - midright=player.rect.midleft + pygame.math.Vector2(0, 16)) + midright=player.animation.rect.midleft + pygame.math.Vector2(0, 16)) elif direction == 'down': self.rect = self.image.get_rect( - midtop=player.rect.midbottom + pygame.math.Vector2(-10, 0)) + midtop=player.animation.rect.midbottom + pygame.math.Vector2(-10, 0)) else: self.rect = self.image.get_rect( - midbottom=player.rect.midtop + pygame.math.Vector2(-10, 0)) + midbottom=player.animation.rect.midtop + pygame.math.Vector2(-10, 0)) diff --git a/entities/player.py b/entities/player.py index 801aec1..cbb1051 100644 --- a/entities/player.py +++ b/entities/player.py @@ -198,28 +198,33 @@ class Player(pygame.sprite.Sprite): else: return False + def agent_update(self): + + # Get the current state + self.get_current_state() + + # Choose action based on current state + action, probs, value\ + = self.agent.choose_action(self.state_features) + + # Apply chosen action + self._input.check_input(action, + self.stats.speed, + self.animation.hitbox, + self.obstacle_sprites, + self.animation.rect, + self) + + self.agent.remember(self.state_features, action, + probs, value, self.stats.exp, self.is_dead()) + + self.get_current_state() + def update(self): if not self.is_dead(): - # Get the current state - self.get_current_state() - # Choose action based on current state - action, probs, value\ - = self.agent.choose_action(self.state_features) - # Apply chosen action - self._input.check_input(action, - self.stats.speed, - self.animation.hitbox, - self.obstacle_sprites, - self.animation.rect, - self) - - self.score = self.stats.exp - self.agent.remember(self.state_features, action, - probs, value, self.stats.exp, self.is_dead()) - - self.get_current_state() + self.agent_update() # Cooldowns and Regen self.stats.health_recovery() @@ -232,6 +237,4 @@ class Player(pygame.sprite.Sprite): self.get_status() self.animation.animate( self._input.status, self._input.combat.vulnerable) - self.image = self.animation.image - self.rect = self.animation.rect self._input.cooldowns(self._input.combat.vulnerable) diff --git a/figures/actor_loss.png b/figures/actor_loss.png index 78ba7b8..f1a07df 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 6cc5bc9..d3cae22 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 27ce63c..fcc8638 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 f48efb8..199003c 100644 Binary files a/figures/total_loss.png and b/figures/total_loss.png differ diff --git a/pneuma.py b/pneuma.py index cabc0ef..2efa964 100644 --- a/pneuma.py +++ b/pneuma.py @@ -203,8 +203,10 @@ if __name__ == "__main__": # Check for new best score if player.stats.exp > best_score[player.player_id]: - print(f"\nNew best score:\t {player.stats.exp}\ - \nOld best score: \t {best_score[player.player_id]}") + print(f"\nNew best score for player {player.player_id}:\ + {player.stats.exp}\ + \nOld best score for player {player.player_id}: \ + {best_score[player.player_id]}") best_score[player.player_id] = player.stats.exp @@ -223,8 +225,7 @@ if __name__ == "__main__": # End of training session print("End of episodes.\ - \n Exiting game...") - game.quit() + \nExiting game...") plt.figure() plt.title("Player Performance") @@ -261,4 +262,4 @@ if __name__ == "__main__": for total in total_loss: plt.plot(total) plt.savefig(f"{figure_folder}/total_loss.png") - plt.show() + game.quit()