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. It's 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. It looks at the spells and items by what the ROM says they do, so one it rarely saw is still judged by its power and cost.
The first long run went from 38% to 88% of the fights won, and the fights got shorter, from about 9000 frames to 3700. It also learned to use items and spells, not only Fight.
When it breaks¶
When a step runs too long or the CPU halts, the worker writes a report: a savestate from before the step, one at the hang, a screenshot, the registers, the call stack with the symbols, and the step replayed under the tracer up to the crash. The report is stamped with the build it replays on, and that starting point is never picked again, so one bad fight doesn't eat the run.
A graphics glitch doesn't hang anything, so there is a "security TV": every worker's screen tiled in one window. If I click on one, it files a report too.
Hunt mode is what I run on a new build. It just plays battles without learning, and at the end I get a summary of what crashed.
What it found¶
In the patch, fixed:
- The battle inventory drew from the NMI and didn't restore DrawText's pointers. 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. That ended on a
BRK. - The pool for the bank
$01trampolines claimed more than what was moved out of it, so it overwrote the game's battle animation code, the one summons and Teleport call. Also aBRK.
In the patch, not fixed yet: long monster names lose their first letters in the battle window. That one doesn't hang, I saw it on the security TV.
In the original Japanese game, still open: a battle that spins at $02:EA4x, which also happens from a battle the game starts by itself, and a wait on the sound driver upload that never ends. That last one could also be kintsuki's SPC timing, I didn't look yet.