TAS Golf
In the style of a tool-assisted speedrun with a code-golf twist, the goal of this challenge is to complete World 1-1 of the original Super Mario Bros game for the NES in your chosen programming language in as few bytes as possible, using only the in-game controller inputs in the format I'll describe below. Your program must output to stdout
a list of lines in this format, created specifically for this challenge:
up down left right start select A B
Starting with the first frame, each newline represents the inputs for Controller 1 for a particular frame. The order of buttons per frame does not matter, and they can be separated by any amount of non-newline whitespace. All or none or some of the button names can be included per line. For example, a simple Python program that presses the D-pad right for 3 frames and then presses A might look like this:
for _ in range(3): print('right')
print('A')
And its output (which I would feed into my emulator to verify) would be:
right
right
right
A
Here, we define 'success' as reaching the flag at the end of World 1-1 pictured above. The score for this example Python submission, if it succeeded (which it doesn't), would be 44 bytes, or the original length of the Python program.
For an example working input file I created based on the current fastest TAS, see this Github Gist: https://gist.github.com/anonymous/6f1a73cbff3cd46c9e1cf8d5c2ff58e1 Note that this file completes the entire game.
There is no way to enter subframe inputs. There is also no way to enter inputs in Player 2's controller, but that also shouldn't be necessary (or useful) for completing the level or game.
The version of SMB used will be the original USA / Japan iNES ROM (md5sum 811b027eaf99c2def7b933c5208636de -- the USA version is the exact same as the Japanese version so either will work, the ROM is commonly labeled Super Mario Bros (JU) (PRG 0)
or similar).
To test the submissions, I will run the programs, pipe their stdout
into an input.txt file, and load them into FCEUX using this Lua script mario.lua
I wrote for this challenge:
for line in io.lines('input.txt') do
local t = {}
for w in line:gmatch("%S+") do
t[w] = true;
end;
joypad.set(1, t);
emu.frameadvance();
end;
while (true) do
emu.frameadvance();
end;
The specific command I'll be using is fceux mario.nes --loadlua mario.lua
. There is no time limit to the programs, though they must eventually terminate.
This is a little Bash one-liner I made to convert a FCEUX movie (.fm2) file to an input.txt for my script, if it helps:
cat movie.fm2 | cut -d'|' -f 3 | sed 's/\.//g' | sed 's/R/right /g' | sed 's/L/left /g' | sed 's/D/down /g' | sed 's/U/up /g' | sed 's/T/start /g' | sed 's/S/select /g' | sed 's/B/B /g' | sed 's/A/A /g' | tail -n +13 > input.txt
For reference, here is a full-resolution map of World 1-1 (open the image in a new tab for full resolution):
(source: mariouniverse.com)
Note: At first glance, this may seem like a Kolmogorov complexity challenge on my given input.txt file. However, in reality the challenge is more complex than that because (a) the input.txt I provided is definitely not the shortest possible and (b) there has never been an attempt to create the shortest possible set of keypresses for SMB in this format. The 'fewest buttons possible' known TAS is different because it allows for holding of buttons for a long time, which would add length to the desired output in this challenge.