Add game wrapper for Pac-Man#419
Open
Manetas151 wants to merge 1 commit into
Open
Conversation
Owner
|
Thank you for your PR! I haven't forgotten about it, I just need to find the time to review. |
Baekalfen
reviewed
Jun 3, 2026
Baekalfen
left a comment
Owner
There was a problem hiding this comment.
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 |
Comment on lines
+39
to
+40
| def bcd(b): | ||
| return (b >> 4) * 10 + (b & 0x0F) |
Owner
There was a problem hiding this comment.
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 |
Comment on lines
+60
to
+61
| self._tile_cache_invalid = True | ||
| self._sprite_cache_invalid = True |
Owner
There was a problem hiding this comment.
You should call super().post_tick() instead
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 |
Owner
There was a problem hiding this comment.
This should be handled by start_game in your wrapper
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]) | ||
| ) |
Owner
There was a problem hiding this comment.
You can use:
from pyboy.utils import dec_to_bcd, bcd_to_dec| score = _read_score(pyboy) | ||
| assert score >= prev, f"Score decreased: {prev} -> {score}" | ||
| prev = score | ||
| if pyboy.memory[0xD641] == 0: |
Owner
There was a problem hiding this comment.
What is this address? It's used in multiple tests, so best declare it globally.
| }, | ||
| ext_modules=[Extension("", [""])], # Added to trigger a binary wheel | ||
| ) | ||
| ) No newline at end of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adding a wrapper for pac-man (non colored)
MD5: cd9027e147f4605f26ee261c537441b3
SHA256: 4a43f491e4c5cef282960b06d23133ff3cb234e228fd21fe1e99958eee8c4971
The wrapper provides for now:
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.