Skip to content

Add game wrapper for Pac-Man#419

Open
Manetas151 wants to merge 1 commit into
Baekalfen:masterfrom
Manetas151:pac-man
Open

Add game wrapper for Pac-Man#419
Manetas151 wants to merge 1 commit into
Baekalfen:masterfrom
Manetas151:pac-man

Conversation

@Manetas151

Copy link
Copy Markdown

Adding a wrapper for pac-man (non colored)

MD5: cd9027e147f4605f26ee261c537441b3
SHA256: 4a43f491e4c5cef282960b06d23133ff3cb234e228fd21fe1e99958eee8c4971

The wrapper provides for now:

  • score
  • lives left
  • level
  • game_over()
  • start_game()
  • reset_game()

Tests are included in tests/test_pac_man.py

I found the ROM in multiple websites and all ROM's had the same hash value.

I'm planning to add more features to the wrapper but i wanted to get some feedback first.

@Baekalfen

Copy link
Copy Markdown
Owner

Thank you for your PR! I haven't forgotten about it, I just need to find the time to review.

@Baekalfen Baekalfen left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. I think it's a solid foundation for your future work

Comment on lines +29 to +31
ADDR_SCORE_LO = 0xD637 # tens + ones
ADDR_SCORE_MID = 0xD638 # thousands + hundreds
ADDR_SCORE_HI = 0xD639 # hundred-thousands + ten-thousands

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

Comment on lines +39 to +40
def bcd(b):
return (b >> 4) * 10 + (b & 0x0F)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can find bcd->dec and dec->bcd functions in utils:

from pyboy.utils import dec_to_bcd, bcd_to_dec

Comment on lines +17 to +26
def enabled(self):
import hashlib

try:
with open(self.pyboy.gamerom_file, "rb") as f:
rom_hash = hashlib.md5(f.read()).hexdigest()
return rom_hash == "cd9027e147f4605f26ee261c537441b3"
except Exception as e:
logger.error(f"Error occurred while checking ROM hash: {e}")
return False

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed. Unused.

Comment on lines +60 to +61
self._tile_cache_invalid = True
self._sprite_cache_invalid = True

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should call super().post_tick() instead

Comment thread tests/test_pac_man.py
Comment on lines +15 to +24
"""Start the emulator and advance to the first playable frame."""
pyboy = PyBoy(rom, window="null")
pyboy.set_emulation_speed(0)
for _ in range(700):
pyboy.tick(1, False)
pyboy.button("start")
pyboy.tick(1, False)
for _ in range(1000):
pyboy.tick(1, False)
return pyboy

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be handled by start_game in your wrapper

Comment thread tests/test_pac_man.py
Comment on lines +27 to +34
def _read_score(pyboy):
def bcd(b):
return (b >> 4) * 10 + (b & 0xF)
return (
bcd(pyboy.memory[0xD639]) * 10_000 +
bcd(pyboy.memory[0xD638]) * 100 +
bcd(pyboy.memory[0xD637])
)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use:

from pyboy.utils import dec_to_bcd, bcd_to_dec

Comment thread tests/test_pac_man.py
score = _read_score(pyboy)
assert score >= prev, f"Score decreased: {prev} -> {score}"
prev = score
if pyboy.memory[0xD641] == 0:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this address? It's used in multiple tests, so best declare it globally.

Comment thread setup.py
},
ext_modules=[Extension("", [""])], # Added to trigger a binary wheel
)
) No newline at end of file

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated formating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants