fixed three bugs

This commit is contained in:
Vasilis Valatsos 2023-11-29 12:10:04 +01:00
parent 84000dd28b
commit c7ddaa630c
12 changed files with 39 additions and 35 deletions

Binary file not shown.

BIN
agents/saved_models/A1 Normal file

Binary file not shown.

Binary file not shown.

BIN
agents/saved_models/C1 Normal file

Binary file not shown.

View file

@ -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)

View file

@ -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))

View file

@ -198,11 +198,11 @@ class Player(pygame.sprite.Sprite):
else:
return False
def update(self):
def agent_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)
@ -215,12 +215,17 @@ class Player(pygame.sprite.Sprite):
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()
def update(self):
if not self.is_dead():
self.agent_update()
# Cooldowns and Regen
self.stats.health_recovery()
self.stats.energy_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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View file

@ -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
@ -224,7 +226,6 @@ if __name__ == "__main__":
# End of training session
print("End of episodes.\
\nExiting game...")
game.quit()
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()