Now that we successfully downloaded a replay, let's finally extract the errorstream of an entire game.
This allows to reproduce every step, as long as our own bot is deterministic.
By arena bot prints every input given by the referee directly to stderr so that I can read it again later.
import json, os
# read the replay from file
withopen('replay.json', 'r') as f:
replay = json.loads(f.read())
stderr = 
for frame in replay['success']['frames']:
ifnot'stderr'in frame.keys(): continue
for err in frame['stderr'].split('\n'):
# some of my stderr lines aren't referee input. I marked them with '#' to filter them
ifnot err.startswith('#'): stderr.append(err)
#write the errorstream to the file 'input.txt'
withopen('input.txt', 'w+') as f:
Now we saved all the referee input to a single file. Now we can copy it in our terminal as input. Or we configure the IDE to read from file.
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.