Skip to content

Commit

Permalink
Add game over logic
Browse files Browse the repository at this point in the history
  • Loading branch information
msosav committed Aug 1, 2024
1 parent 485e2fd commit fb8e102
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions config/gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
from pyboy import PyBoy
from pyboy.utils import WindowEvent
from .memory_addresses import *


class ZeldaGymEnv(gym.Env):
Expand Down Expand Up @@ -60,10 +61,9 @@ def step(self, action):
else:
self.pyboy.send_input(self.valid_actions[action])

self.pyboy.tick(1)
self.pyboy.tick()

# TODO: Implement game over logic
done = self.pyboy.game_wrapper.game_over
done = self.__game_over()

self._calculate_fitness()
reward = self._fitness-self._previous_fitness
Expand All @@ -74,13 +74,17 @@ def step(self, action):

return observation, reward, done, truncated, info

def __game_over(self):
if self.pyboy.memory[ADDR_CURRENT_HEALTH] == 0:
return True
return False

def _calculate_fitness(self):
self._previous_fitness = self._fitness

# TODO: Implement reward logic
self._fitness = 0

# TODO: Implement reset game
def reset(self, **kwargs):
try:
with open(self.state_path, 'rb') as state_file:
Expand Down

0 comments on commit fb8e102

Please sign in to comment.