Today I want to tell the story of what happened to the AI that I programmed for a game. As a developer of AI code in games, you typically write the behaviour and decisions of character in the world that are not directly under the player's control. We call them Non Player Characters, or NPCs.
These characters should conduct their business in the game world so that it mimics intelligence. They need to plan their actions to achieve goals in this world.
Sometimes though, your AI creations can outsmart the programmer. They can decide to do things that the programmer did not plan for, or expect. This is called emergent behaviour. They end up doing stuff that was not explicitly specified by the programmer. They figured out something new, unforeseen the the developer.
This is a story of such emergent behaviour.
So I had prototyped a test world where the AI could perform a set of actions. And the AI knows when/where those actions are applicable, and what its effects would be. In this test world there was a notion of travelling, like going to a shop, or the woods. Actions like cutting trees was available, as was buying, selling, and other basic actions.
Now, to test my code, I had set up the world where I expected my AI to obtain lumber (Goal for the plan was to have lumber.) When I executed my code, I was expecting my AI code (the planner) to come up with the following plan:
- Go to shop
- Buy axe
- Go to forest
- Chop tree
- Drop axe
- Pick up lumber
So I run the code, and the AI comes back with a plan to obtain lumber. And the plan started with:
- Go to forest
- ..
Oh no! I have a bug in my code. Why did my AI decide to directly going to the forest, without first getting an axe? But when I examined the rest of the AI's plan, I was overjoyed. Almost like a proud parent, seeing its virtual child do something smart!
- Go to forest
- Pick up firewood
- Go to store
- Sell firewood
- Buy axe
- Go to forest
- Chop tree
- Drop axe
- Pick up timber
Oooh Yeah!!! How amazing.
So in my test world, I had not given my NPC any money. And it is smart enough to know that without money, you can't buy an axe! But because I had added the concept of selling in the game world too, and picking up random stuff, the AI had out smarted me. It decided it should get something to sell in the shop first. That's why it went directly to the forest.
Being outsmarted by your own AI code is a great feeling! I hope it will happen some more in the future.
Bram
ᴘᴏsᴛsᴄʀɪᴘᴛᴀ
- The action planner I used when writing this code, I have open sourced as General Purpose Goal Oriented Action Planning.
- I made a free game that uses GPGOAP called Children of Orc.