fixed three bugs
BIN
agents/saved_models/A1
Normal file
BIN
agents/saved_models/C1
Normal file
|
@ -17,12 +17,12 @@ class MagicPlayer:
|
||||||
player.stats.health = player.stats.stats['health']
|
player.stats.health = player.stats.stats['health']
|
||||||
self.animation_player.generate_particles(
|
self.animation_player.generate_particles(
|
||||||
'aura',
|
'aura',
|
||||||
player.rect.center,
|
player.animation.rect.center,
|
||||||
groups)
|
groups)
|
||||||
|
|
||||||
self.animation_player.generate_particles(
|
self.animation_player.generate_particles(
|
||||||
'heal',
|
'heal',
|
||||||
player.rect.center + pygame.math.Vector2(0, -50),
|
player.animation.rect.center + pygame.math.Vector2(0, -50),
|
||||||
groups)
|
groups)
|
||||||
|
|
||||||
def flame(self, player, cost, groups):
|
def flame(self, player, cost, groups):
|
||||||
|
@ -41,17 +41,17 @@ class MagicPlayer:
|
||||||
for i in range(1, 6):
|
for i in range(1, 6):
|
||||||
if direction.x:
|
if direction.x:
|
||||||
offset_x = direction.x * i * TILESIZE
|
offset_x = direction.x * i * TILESIZE
|
||||||
x = player.rect.centerx + offset_x + \
|
x = player.animation.rect.centerx + offset_x + \
|
||||||
randint(-TILESIZE // 3, TILESIZE // 3)
|
randint(-TILESIZE // 3, TILESIZE // 3)
|
||||||
y = player.rect.centery + \
|
y = player.animation.rect.centery + \
|
||||||
randint(-TILESIZE // 3, TILESIZE // 3)
|
randint(-TILESIZE // 3, TILESIZE // 3)
|
||||||
self.animation_player.generate_particles(
|
self.animation_player.generate_particles(
|
||||||
'flame', (x, y), groups)
|
'flame', (x, y), groups)
|
||||||
else:
|
else:
|
||||||
offset_y = direction.y * i * TILESIZE
|
offset_y = direction.y * i * TILESIZE
|
||||||
x = player.rect.centerx + \
|
x = player.animation.rect.centerx + \
|
||||||
randint(-TILESIZE // 3, TILESIZE // 3)
|
randint(-TILESIZE // 3, TILESIZE // 3)
|
||||||
y = player.rect.centery + offset_y + \
|
y = player.animation.rect.centery + offset_y + \
|
||||||
randint(-TILESIZE // 3, TILESIZE // 3)
|
randint(-TILESIZE // 3, TILESIZE // 3)
|
||||||
self.animation_player.generate_particles(
|
self.animation_player.generate_particles(
|
||||||
'flame', (x, y), groups)
|
'flame', (x, y), groups)
|
||||||
|
|
|
@ -23,13 +23,13 @@ class Weapon(pygame.sprite.Sprite):
|
||||||
# Sprite Placement
|
# Sprite Placement
|
||||||
if direction == 'right':
|
if direction == 'right':
|
||||||
self.rect = self.image.get_rect(
|
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':
|
elif direction == 'left':
|
||||||
self.rect = self.image.get_rect(
|
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':
|
elif direction == 'down':
|
||||||
self.rect = self.image.get_rect(
|
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:
|
else:
|
||||||
self.rect = self.image.get_rect(
|
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))
|
||||||
|
|
|
@ -198,28 +198,33 @@ class Player(pygame.sprite.Sprite):
|
||||||
else:
|
else:
|
||||||
return False
|
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):
|
def update(self):
|
||||||
|
|
||||||
if not self.is_dead():
|
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.agent_update()
|
||||||
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()
|
|
||||||
|
|
||||||
# Cooldowns and Regen
|
# Cooldowns and Regen
|
||||||
self.stats.health_recovery()
|
self.stats.health_recovery()
|
||||||
|
@ -232,6 +237,4 @@ class Player(pygame.sprite.Sprite):
|
||||||
self.get_status()
|
self.get_status()
|
||||||
self.animation.animate(
|
self.animation.animate(
|
||||||
self._input.status, self._input.combat.vulnerable)
|
self._input.status, self._input.combat.vulnerable)
|
||||||
self.image = self.animation.image
|
|
||||||
self.rect = self.animation.rect
|
|
||||||
self._input.cooldowns(self._input.combat.vulnerable)
|
self._input.cooldowns(self._input.combat.vulnerable)
|
||||||
|
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 22 KiB |
11
pneuma.py
|
@ -203,8 +203,10 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# Check for new best score
|
# Check for new best score
|
||||||
if player.stats.exp > best_score[player.player_id]:
|
if player.stats.exp > best_score[player.player_id]:
|
||||||
print(f"\nNew best score:\t {player.stats.exp}\
|
print(f"\nNew best score for player {player.player_id}:\
|
||||||
\nOld best score: \t {best_score[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
|
best_score[player.player_id] = player.stats.exp
|
||||||
|
|
||||||
|
@ -223,8 +225,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# End of training session
|
# End of training session
|
||||||
print("End of episodes.\
|
print("End of episodes.\
|
||||||
\n Exiting game...")
|
\nExiting game...")
|
||||||
game.quit()
|
|
||||||
|
|
||||||
plt.figure()
|
plt.figure()
|
||||||
plt.title("Player Performance")
|
plt.title("Player Performance")
|
||||||
|
@ -261,4 +262,4 @@ if __name__ == "__main__":
|
||||||
for total in total_loss:
|
for total in total_loss:
|
||||||
plt.plot(total)
|
plt.plot(total)
|
||||||
plt.savefig(f"{figure_folder}/total_loss.png")
|
plt.savefig(f"{figure_folder}/total_loss.png")
|
||||||
plt.show()
|
game.quit()
|
||||||
|
|