BLOG #11 – The GameJam – #1 SpelunkBots

So I mentioned the GameJam in my last post. This took place last Friday (17th October) for 24 hours. The difference with this from previous Jams that have taken place is that there were multiple events that were going on.
The typical ‘make a game in 24 hours’ jam had the theme of ‘Wario ware in 30 seconds’ meaning participants had to make a series of mini games that when strung together lasted no longer than 30 seconds.
There was also a WorkJam taking place for any of the students (particularly final years) that needed extra time in the labs to work on project.
Finally but by no means least there was a SpelunkyJam, which I took part in.

SpelunkySpelunky XBLA Art Work

For those of you unfamiliar, in 2009 Derek Yu, an indie developer, released his open source, procedurally generated, platforming game Spelunky. Players take on the role of the spelunker, traversing caverns looking for treasure and avoiding the enemies and traps within. The procedural nature of the game, combined with the fact that all of the tiles that make up the map are destructible, means that there are many ways in which a player can approach this task.


Developed by Daniel Scales (for his Dissertation) and Tommy Thompson (Course Leader of Computer Games Programming at University of Derby), SpelunkBots is an API that allows users to create AI bots that play Spelunky.
Building on the original GameMaker code and combined with C++ dll, SpelunkBots can be downloaded here.


The role of myself, Jordan RoweChris Fisher and the rest of those taking part was to debug and test the limitations of the API. Alongside this we also gave feedback on the documentation that came with the program in a bid to improve the ease of understanding that new users will have.

SpelunkbotsFileTreeFor those interested

If you have grabbed the folder from the link above the easiest way to get started is to open the version of GameMaker included in the download. From here you can go to: file->open and browse for the SpelunkBots-master->Source->Spelunky_1_1->Spelunkbots.gml file.
You should then be faced with all the files on the left hand side of the screen, the one you are looking for is under Scripts, AI Toolkit, BotScripts and is called ‘PlayerChoice’. This is where all the GML code will go for your bot as well as already containing some examples built by Dan and others.

There are many approaches towards programming your bot, but the most popular at this early stage and the one most commonly used in the examples is to give your bot a goal. This is done by scanning the entire 42*34 level for what we want to find and using the A* Path methods to directly navigate the bot there.
For example:

// GOLD DIGGER The first example bot from the file
// When the bot has no goal..
if (!global.hasGoal)
  //for each column..
  for (i = 0; i < 42; i+=1)
    //and each row..
    for (j = 0; j < 34; j+=1)
      //look for a piece of gold.
      if (GetNumberOfCollectableTypeInNodeXY(global.spGoldBar,i,j) > 0)
        //Now set the target for your bot.
        global.targetX = i * 16;
        global.targetY = j * 16;
        global.hasGoal = true;
        global.itemGoal = true;
        CreateAStarPathFromXYtoXY(x/16,y/16, global.targetX/16, global.targetY/16);
        return 0;
// When we already have a goal
  // Go towards the x point of the closest node on the path
  if (global.playerPositionX < (GetNearestXPos(global.playerPositionX / 16, global.playerPositionY / 16) * 16))
    global.goRight = true;
    global.goLeft = true;
  // Jump if below the nearest y point..
  if (global.playerPositionY > (GetNearestYPos(global.playerPositionX / 16, global.playerPositionY / 16) * 16) + 8)
    global.playerJump = true;
  // but don't jump unnecessarily.
    global.playerJump = false;

The reason for the ‘/16’ everywhere is that each tile is made of 16*16 pixels. Now I have also missed some of the validation checks that Dan included, but they haven’t hugely impacted on the principles of the code, which can be viewed in the actual API.
Having reached the goal the bot will now stop as the goal doesn’t get set back to false.

Unfortunately there are limitations to this approach:
-There is a fog based element to the maps and procedural generation with only allow the bot to scan what has already been shown on screen. This means if no goal is within sight then the bot will not move.
-Furthermore this starts to get complex as you try to change through different scenarios the bot may be faced with. Adding goals to deal with gold, enemies, idols and exits all make the task more complicated.
What should your bot do if there are 2 enemies on screen? What happens if they switch places?

Issue with platforming in A* search
The logical choice would be to jump onto the platform on the right and then to the block being targeted (indicated by the blue line).
A* Search will not go off the screen
As the rest of the map has not been explored the search algorithm will not be able to create a path to the gold, so tries to head straight there.

-Also the search for a goal always scanning each column of the map, from top to bottom, left to right, means that the A* Path will always route for the top left most goal item. Even if it is unreachable. At the time of writing the current state of the path search will not take into account platforming mechanics or situations when the player has to go off the screen to find a route round to where the objective is.
-Finally we discovered an issue with player created maps (loaded by pressing f3 on the home screen) and the A* search. Each tile is referred to as a node by the search, but in custom maps these nodes are not given the correct value to show up on the search. Whether this is a bug with Spelunky itself or with the API remains to be seen, however anyone trying out their bot in custom levels needs to be aware that to do so they need to load it through the level constructor (F2 at the title screen).

Despite this we gained a lot from the experience and pointed Dan and Tommy towards the direction they want to head, where they will one day be running the world’s first SpelunkBot AI competition.