Last week, a coworker let me know about this. It’s been on Slashdot and such, but I’m a little behind on my feeds. For some reason, the competition intrigued me so I’ve put together a set of Perl classes that will allow agents written in Perl to control the Mario AI simulator using the server agent. I considered trying Java, but I started and quickly remembered why I hate Java, so I quit that and wrote this up over the weekend instead. You can fork it and give it a look here.
It includes a very stupid and blind robot for testing at this point. However, it is able to get through most levels I’ve tried on difficulty 0 (though, not many on any higher difficulty). Once you install that and fetch the latest JAR file from the Mario AI competition site:
You can then run an agent via:
java -jar iMario.jar -server on
to start the server, then:
cd AI-Mario bin/agent.pl
This will run the blind Perl agent (named
AI::Mario::Agent::Simple) on the same level over and over. A more interesting run might be:
bin/agent.pl --config AI::Mario::Config::Random -o level_difficulty=2
This will run the same agent through a random series of levels (restarting each time the agent wins or loses) and sets the level difficulty to 2—which means, the simple agent nearly always loses.
The system is built with Modern Perl (i.e. Moose) and uses POE and POE::Declarative to talk to the Mario AI server agent. You can implement new configuration (to customize how options are set at the start of each run) and agent and set them to run using the arguments available on the CLI.
To write an agent, for example, you just need to create a class that does the
AI::Mario::Agent role and implements the required methods.
- name: should return the agent name to be sent to the server agent as greetings
- reset: a method called to reset the agent when a simulation is about to start
- update: a method called during each frame, given an observation object (see
AI::Mario::Observation) and should set the
runcontrols appropriately to keep moving.
- fitness: this is called at the end of the simulation with a fitness report to tell the agent how well it did (see
Then, you can run your agent via:
bin/agent.pl --agent MyAgentClass -p foo=1
where you can pass a series of parameters to the agent constructor using the
I plan to add a bit more to it, but the interface is mostly set.
I’m not even sure they’ll accept a Perl submission, but it seems to be implied by the instructions on the site. I’ve asked to be sure. If I can confirm that, I’ll also add a
Makefile.PL and such so that the solution can be packaged with all the required libraries to make it run.
I still haven’t decided whether or not to enter or just goof around, but whatever. :)
Update: Julian already replied. Yes, Perl submissions would be accepted. I’ll definitely try to add a submission script which will help build all the requirements to submit.