The AI-controlled player fighting orcs in a Little Rogue dungeon
← All work

Little Rogue

A top-down, turn-based roguelike dungeon crawler played entirely by an AI I designed.

What I did

  • AI decision-making with a behavior tree.
  • A* pathfinding to find the stairs to the next level.
  • The AI's actions: fighting, healing and using items.

Played by AI, against AI

To teach AI in video games, our class was asked to design an AI that could play a game for as long as possible, before either the game ended or the AI character, inevitably, died.

I chose a roguelike, so I faced the latter. It’s a simple game:

  • two types of enemies (Orc and Ogre)
  • six items (healing potion, lightning/fire/confusion scrolls, sword and shield)
  • stairs to the next level
  • a level system (health and damage)
  • built with Python and PyGame

My contributions focus on the AI’s decision-making, actions and pathfinding.

The pathfinding window showing the route to the stairs

Finding the way

To progress, the AI has to find the stairs that lead to the next level. For that I wrote a pathfinding function using the A* search algorithm.

A*’s main drawback, high space complexity, has little effect on a game this simple that uses so little memory.

In broad terms, the algorithm assigns a cost to each tile and finds the path with the lowest total cost from the AI character to the stairs.

A* pathfinding code

Decide… as best you can

Once the path is known, every action is a decision waiting to be made. Conditions, context and available information all come into play when choosing what to do next.

To let the AI run those checks and decide what to do based on that information, behavior trees are the go-to.

Behavior tree code