1ALttP Randomizer Bot
2====================
3
4The goal is to write a bot that can play [_Legend of Zelda: A Link to the Past_'s Randomizer](https://alttpr.com/en) in a similar way that a human would.
5
6Unlike a Tool-Assisted Speedrun (_TAS_) of the original game, the _Randomizer_ shuffles the locations of items around, so the bot can't blindly follow a script verbatim.
7
8The bot reads out chunks of memory from the emulated SNES to understand what is on-screen: it's not operating on the video/images shown on screen. For fairness, it doesn't use any data that wouldn't be knowable to a human player: e.g. it doesn't peak inside chests before opening them.
9
10Architecture
11------------
12
13The bot is written as a library that gets linked into a slightly-modified [Snes9x](https://github.com/snes9xgit/snes9x) emulator. There are 2 key functions in the interface:
14
15- `void ap_tick(uint32_t frame, uint16_t * joypad)`
16    - This function is called each frame, and blocks emulation until the bot returns. The bot can set the controller state with the `*joypad` outparameter.
17- `uint8_t * (*base)(uint32_t addr)` on `struct ap_snes9x`
18    - This function can be used by the bot to get the memory address for a given SNES virtual memory address.
19
20The overall code quality is pretty bad, and is mostly shaped around rapid iteration.
21
22
23Videos in action
24----------------
25
26[All media](https://github.com/zbanks/alttp/tree/media)
27
28- [24 minutes of gameplay, from 2020/10/04, sped up 10x](https://github.com/zbanks/alttp/blob/media/alttp_20200104_10x.mp4)
29    - Randomizer Settings: Open mode, Sword on Uncle, No Glitches, Defeat Ganon
30    - Cheating: infinite health, bombs, and arrows
31    - Hits about ~45 checks, clears Eastern Palace
32
33Credits
34-------
35
36This wouldn't be possible without the crazy amount of reverse-engineering effort put into this game. 
37
38- MathOnNapkin's Zelda 3 RAM/ROM/SRAM documentation
39- MathOnNapkin's Zelda 3 Annotated Disassembly
40- wiiqwertyuiop's Zelda 3 Annotated Disassembly