AI DIY – Knowledge Representation

Introduction

Knowledge representation is the task of understanding how the world around us works and how difficult that will make it for a rational agent to act within it.  For those who are not yet familiar with the topic, check out part 5 of the AI 101 series, where we cover the topic in brief.    In this exercise, we look at what problems may arise when taking new or existing games and attempting to model them for an AI to play.

For this exercise, we’re interested in AI that would either act in the place of the player, or be an active character in their world.  This can mean playing as the opponent in a game of Chess, or an innkeeper in the likes of Elder Scrolls: Skyrim.  This will help us understand what parts of the world we need to model and the problems that might arise when trying to make all this manage when we try to search for intelligent decisions.

Part 1: Select a Game

We can begin by select an existing game that you are familiar with. This can be a board game, card game or video game.  Write down key information such as:

  • A quick summary of what the game is about: this can be expressed by themes, narratives etc.
  • How many players can participate?
  • How players participate in the game?
  • What are the rules of the game?
  • What conditions allow for a player to win that game?

Alternatively you can devise a game of your own, with a clear series of rules that dictate play.  Though I would encourage taking the original route unless you really want to push yourself.

Now I would encourage you to start with something fairly small. A game that you could quick walk through the following questions without too much hassle.  The larger the game, the more lengthy (and complicated) your answers may become.

Part 2: Understand Your Game

Now that we have selected a game and identified what it is and how it works.  Let’s begin assessing it for the purposes of an AI agent.  Take your game and assess the following criteria:

Determinism: If we take a particular action in a game, do we always know the outcome?  This is complicated by game elements such as dice, given that – while they only have one of six outcomes – we cannot predict with 100% confidence what the dice roll would be.

Observability: Can we see everything that is happening in the game?  Is there any information that is hidden from us?  This will have an impact on our decisions given we can only make educated guesses as to what is currently happening.  Card games are often guilty of this, given that players will each be holding cards that only they can see.  Even something as simple as Snap is partially-observable because while we can guess what cards are still to be revealed, we do not know who is actually holding them.

Single/Multi-Agent: Are there any other agents that can have an impact on our performance?  Is it solely the player who is in control, or are there other agents in play who can instigate change in the world?

Discrete: Is the game discretised?  Or is it a continuous event?  Of course if it is a video game then on some level it is discretised given that it will run on a fixed number of frames per second.  However, consider the reality of the problem rather than the methods of its execution through programming.

A Prepared Example

To help with this topic, the video accompanying this article gives a walk-through of how these principles apply to a specific game.  I’d hold off until you have completed this exercise before watching the video.  Unless you’re the cheating type… in which case all of my pleas for you to stop mean nothing.

Enjoying AI and Games? Please support us on Patreon!
Tommy Thompson Written by:

Tommy is the writer and producer of AI and Games. He’s a senior lecturer in computer science and researcher in artificial intelligence with applications in video games. He’s also an indie video game developer with Table Flip Games. Because y’know… fella’s gotta keep himself busy.