Add test suite for memory reader, state builder, and pathfinding - #1
Open
ch3ronsa wants to merge 1 commit into
Open
Add test suite for memory reader, state builder, and pathfinding#1ch3ronsa wants to merge 1 commit into
ch3ronsa wants to merge 1 commit into
Conversation
79 tests covering: - RedBlueMemoryReader: player, party, bag, battle, dialog, map, flags, status decoding, Gen-1 encoding table, name tables - State builder: build_game_state sections, error handling, partial failures, build_state_summary output - Pathfinding: A* search, collision maps, wall avoidance, manhattan distance, neighbors, navigate, path_length All tests use mock emulator (no ROM required).
Author
|
On ROM-based integration tests: These tests are intentionally mock-based because Pokemon ROMs are copyrighted and can't be included in the repo or CI. The mock emulator simulates a 64KB RAM buffer with the same That said, integration tests with a real ROM would be valuable for verifying end-to-end behavior. A possible approach: ROM_PATH = Path(os.environ.get("POKEMON_ROM_PATH", ""))
@pytest.mark.skipif(not ROM_PATH.exists(), reason="ROM not available (set POKEMON_ROM_PATH)")
def test_real_emulator_reads_player():
emu = PyBoyEmulator(str(ROM_PATH))
reader = RedBlueMemoryReader(emu)
# advance a few frames, then verify state reads don't crash
...Users with a ROM could run: Happy to add this as a follow-up if the project wants to support it. |
teknium1
added a commit
that referenced
this pull request
Jun 2, 2026
Adds RAM-based walkability so the agent navigates with ground truth instead of guessing from pixels (the #1 cause of getting lost). - collision.py: reads wTileMap (0xC3A0) + wCurMapTileset (0xD367), maps the on-screen 20x18 tile grid to the game's 10x9 walkable block grid, and classifies each block via the authoritative per-tileset collision lists from pokered data/tilesets/collision_tile_ids.asm (all 24 tilesets). Player is locked to cell E5; sampling uses the correct +1 row offset (player standing tile is wTileMap (8,9)). Verified 40/40 move predictions against the live emulator across a walking path. - overlay.py: render_grid_overlay() draws a labelled A1..J9 grid; optional walkable= arg tints cells green (walkable) / red (blocked) for an unambiguous spatial view (great for the agent and the stream). - server.py: /state now carries a 'collision' block (grid + ASCII) for Red; new GET /map/ascii (text) and GET /screenshot/grid (annotated PNG). - Tests: test_collision.py (pure-data geometry + tileset tables). Experiment finding: an ASCII collision map is the most reliable + cheapest navigation input for the agent; the tinted grid image is the best stream visual; raw-pixel guessing is the weakest. Wire both in accordingly.
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.
Summary
Adds the first test suite for the project as mentioned in the README's contribution areas ("Tests for memory readers and state builders").
79 tests across 3 test files, all passing. No ROM or emulator required — tests use a mock emulator with a 64KB RAM buffer.
What's covered
test_memory_reader.py(36 tests)read_player: name, rival, money (BCD), badges, position, facingread_party: single Pokemon, empty party, corrupted count (cap at 6)read_bag: items with quantities, empty bag, terminator handlingread_battle: not in battle, wild encounter with enemy dataread_dialog: inactive, active via text_box_id, active via joy_ignore bitread_map_info: known map (Pallet Town), unknown map IDread_flags: has_pokedex, has_oaks_parcel, pokedex counts_decode_status: OK, poison, paralysis, sleep, multiple statustest_state_builder.py(19 tests)test_pathfinding.py(24 tests)Test plan
pytest tests/ -v— 79 passed in 0.52spyproject.tomlpytest config