A beta tester that plays FF4
· workbench
I wanted to test the hell out of my changes to FF4, and the battle code carries quite a lot of them, so I made betaplayer, a small agent (PPO) that plays battles through kintsuki. Each turn it chooses a real command, spell or item and a target, from real saves, against the formations the game rolls on the field. The spells and items, it looks at them by what the ROM says they do, so one it rarely saw is still judged by its power and cost. On the first long run it went from 38% to 88% of the fights won, the fights got shorter (from about 9000 frames to 3700), and it learned to use items and spells, not only Fight.
When a step runs too long or the CPU halts, the worker writes a report with a savestate from before the step, the call stack with the symbols and the step replayed under the tracer up to the crash. That starting point is never picked again, so one bad fight doesn't eat the run. A graphics glitch doesn't hang anything, so I also have a "security TV" with every worker's screen in one window, and clicking on one files a report too. On a new build I run hunt mode, which just plays battles without learning and gives me a summary of what crashed at the end.
In the patch it found three bugs that are fixed now. The battle inventory drew from the NMI without restoring DrawText's pointers, so the next message read inventory rows as text and ended up in the loop the game uses for an invalid variable. The inventory transfer went back to the game with garbage in A's high byte, and the game used A to index a jump table, which ended on a BRK. And the pool for the bank $01 trampolines claimed more than what was moved out of it, so it overwrote the battle animation code that summons and Teleport call, another BRK.
Long monster names losing their first letters in the battle window, I saw them on the security TV since it doesn't hang anything, and I didn't fix it yet. Two others are in the original Japanese game and still open: a battle that spins at $02:EA4x, also from a battle the game starts by itself, and a wait on the sound driver upload that never ends, which could also be kintsuki's SPC timing, I didn't look yet.