Add FLE-style backtracking with AlphaEvolve integration#13
Conversation
BacktrackManager saves/restores game state via PyBoy save_state/load_state to escape stuck navigation on Route 1. Snapshots on map change and periodically; restores when stuck_turns exceeds threshold. Four new evolvable params (bt_max_snapshots, bt_restore_threshold, bt_max_attempts, bt_snapshot_interval) flow through evolve.py and run_10_agents.py with two new variants: aggressive_bt and no_bt.
- Remove unused `field` import from dataclasses in agent.py - Import `score()` from evolve.py in run_10_agents.py instead of duplicating it
- Reset _oak_wait_done, _pallet_diag_done, _house_diag_done, _lab_phase, _lab_turns, _lab_exit_turns on backtrack restore so one-time game sequences (Oak encounter, lab phases) can re-trigger after restore - Skip periodic snapshots when position matches the last snapshot to avoid poisoning the pool with stuck-adjacent positions
The backtrack guard checked `map_id == 40 AND party_count == 0`, but party_count changes to 1 the moment the agent picks up Charmander. This allowed backtracking to fire immediately after the pickup, wiping out progress. Change guard to `map_id == 40` (entire lab is protected). Also revert Oak trigger to PR #10's proven brute-force approach (4 rounds of mash_a + wait) instead of script-state-aware gating that read 0xD5F1 while still on Pallet Town map where the address is meaningless. ROM test confirms: agent picks Charmander, wins rival battle, exits lab.
ROM Test ResultsRan the agent with backtracking enabled against the real ROM ( Bug Found & Fixed: Backtrack guard was too narrowThe original guard ( The agent picks up Charmander at ~turn 21 of being "stuck", but the backtrack guard immediately lets a restore through because After fix: Full sequence worksAlso fixed: Oak trigger reverted to brute-forceThe script-state-aware Oak trigger (reading Remaining: post-lab navigationAfter exiting the lab, the agent gets stuck at (12,12) / (7,12) on Pallet Town instead of heading north to Route 1. This is a separate navigation issue, not related to backtracking. Test suite
|
Documents the Factorio Learning Environment-inspired backtracking system: snapshot/restore mechanics, evolvable parameters, and Oak's Lab guard. Adds FLE paper to references list.
Summary
BacktrackManagerclass that saves/restores game state via PyBoysave_state/load_stateto escape stuck navigation (e.g. Route 1 y=28 blocker)stuck_turnsexceeds a configurable thresholdbt_max_snapshots,bt_restore_threshold,bt_max_attempts,bt_snapshot_interval) integrated intoevolve.pyscoring, perturbation, and mutation promptsrun_10_agents.pyvariants:aggressive_bt(low threshold, high retries) andno_bt(disabled baseline)Test plan
uv run pytest tests/)uv run scripts/evolve.py <rom> --generations 3 --max-turns 2000— verify backtracking params appear in genomeuv run scripts/run_10_agents.py <rom>— compare backtrack-enabled vs disabled variantsCloses #5