August 2009 Archives

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 left, right, duck, jump, and run controls 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 AI::Mario::Fitness)

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 -p option.

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. :)

Cheers.

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.

I was goofing around with HTML 5 canvas for giggles this week. The canvas allows you to draw using JavaScript to a section of the page. HTML 5 defines a “2d” context, which allows you to draw lines, polygons, images, boxes, etc. You can style your stroke, fill, and shadow, etc. It’s pretty easy to goof around with. Oh, and if you’re using Internet Explorer, these won’t work. You’re out of luck because Microsoft is too cool for canvas.

Box Fractal Renderer

First, I built a box fractal renderer, which are my favorite things to doodle on graph paper.

Fractal Coastline

Then, I played some more with fractals and eventually ended up with this fractal coastline builder. Each view of this will be a little different. Some look more like coastlines than others.

Anyway, just some random goofing off I thought I’d share.

Cheers.

About this Archive

This page is an archive of entries from August 2009 listed from newest to oldest.

July 2009 is the previous archive.

September 2009 is the next archive.

Find recent content on the main index or look in the archives to find all content.