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,11 +198,11 @@ class Player(pygame.sprite.Sprite):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def update(self):
|
def agent_update(self):
|
||||||
|
|
||||||
if not self.is_dead():
|
|
||||||
# Get the current state
|
# Get the current state
|
||||||
self.get_current_state()
|
self.get_current_state()
|
||||||
|
|
||||||
# Choose action based on current state
|
# Choose action based on current state
|
||||||
action, probs, value\
|
action, probs, value\
|
||||||
= self.agent.choose_action(self.state_features)
|
= self.agent.choose_action(self.state_features)
|
||||||
|
@ -215,12 +215,17 @@ class Player(pygame.sprite.Sprite):
|
||||||
self.animation.rect,
|
self.animation.rect,
|
||||||
self)
|
self)
|
||||||
|
|
||||||
self.score = self.stats.exp
|
|
||||||
self.agent.remember(self.state_features, action,
|
self.agent.remember(self.state_features, action,
|
||||||
probs, value, self.stats.exp, self.is_dead())
|
probs, value, self.stats.exp, self.is_dead())
|
||||||
|
|
||||||
self.get_current_state()
|
self.get_current_state()
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
|
||||||
|
if not self.is_dead():
|
||||||
|
|
||||||
|
self.agent_update()
|
||||||
|
|
||||||
# Cooldowns and Regen
|
# Cooldowns and Regen
|
||||||
self.stats.health_recovery()
|
self.stats.health_recovery()
|
||||||
self.stats.energy_recovery()
|
self.stats.energy_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 |
|
@ -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
|
||||||
|
|
||||||
|
@ -224,7 +226,6 @@ if __name__ == "__main__":
|
||||||
# End of training session
|
# End of training session
|
||||||
print("End of episodes.\
|
print("End of episodes.\
|
||||||
\nExiting 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()
|
||||||
|
|