Skip to content

Commit

Permalink
Fix Kirby score variable and game over condition
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneyjy authored and Baekalfen committed Oct 25, 2023
1 parent 8e27df9 commit 7e69d2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyboy/plugins/game_wrapper_kirby_dream_land.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ cdef class GameWrapperKirbyDreamLand(PyBoyGameWrapper):
cdef public int health
cdef public int lives_left
cdef public int fitness
cdef public int _game_over
15 changes: 12 additions & 3 deletions pyboy/plugins/game_wrapper_kirby_dream_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def __init__(self, *args, **kwargs):
"""The health provided by the game"""
self.lives_left = 0
"""The lives remaining provided by the game"""
self._game_over = False
"""The game over state"""
self.fitness = 0
"""
A built-in fitness scoring. Taking score, health, and lives left into account.
Expand All @@ -53,10 +55,17 @@ def post_tick(self):
self._sprite_cache_invalid = True

self.score = 0
for n in range(4):
self.score += self.pyboy.get_memory_value(0xD070 + n) * 10**n
score_digits = 5
for n in range(score_digits):
self.score += self.pyboy.get_memory_value(0xD06F + n) * 10**(score_digits-n)

# Check if game is over
prev_health = self.health
self.health = self.pyboy.get_memory_value(0xD086)
if self.lives_left == 0:
if prev_health > 0 and self.health == 0:
self._game_over = True

self.lives_left = self.pyboy.get_memory_value(0xD089) - 1

if self.game_has_started:
Expand Down Expand Up @@ -154,7 +163,7 @@ def game_area(self):
return PyBoyGameWrapper.game_area(self)

def game_over(self):
return self.health == 0
return self._game_over

def __repr__(self):
adjust = 4
Expand Down

0 comments on commit 7e69d2e

Please sign in to comment.