A few weeks ago I was playing the Division and it was amazing how quickly the gameplay got repetitive because the NPCs would do the exact same thing. And despite advances in gaming artificial intelligence, each interaction was completely the same.
I thought, “Wouldn’t it be great if the NPCs did not all behave in the exact same way? If when I attacked it or interacted with it the each NPC behaved unexpectedly?” This would keep the player engaged a lot longer. This gave me the idea for ChaosCraft: Trained Neural Networks applied to Minecraft.
What is a Neural Network? Neural Networks are basically decision trees composed of inputs and outputs. For example:
If I see a block of wood, I should walk towards it.
If I see an enemy, I should walk away from it.
Remember the saying “Only the strong survive?” That is where the Genetic Learning Algorithms come into play. Genetic Learning Algorithms create thousands and thousands of Neural Networks and set them to work performing various tasks.
If the Neural Network fails at the task, then it is archived and we move onto the next randomly generated Neural Network. If it passes, then we take those decisions, copy them a few times, and add a few more randomly generated rules to each copy creating a more sophisticated decision tree. Sometimes the copies do better and produce their own more sophisticated copies, sometimes they do worse and get archived.
If we do this for a few thousand generations then the AIs that survive are usually pretty capable of passing whatever tests we give them. This is how most modern image and voice recognition algorithms were created.
In ChaosCraft we use Genetic Learning Algorithms to give each NPC a completely random set of decisions that compose the Neural Network that governs its behavior. An example of a random decision set might be as follows:
- If I see a spider mob, then start digging the block I am standing on.
- If I see water, then walk left.
These rules aren’t really functional at first and most generation 0 NPCs die off, but a few survive. From there we spawn child NPCs that have 90% similar brains to their parents but have an additional 20% randomly generated decisions added to their Neural Network. They are set loose in the world to go about their business and we see if they do any better.
I have seen some interesting behavior generate after only 10 generations. One NPC dug a deep hole to hid in so it wouldn’t get killed, not exactly the most exciting NPC, but it managed to survive. Another NPC would corner itself then place blocks around it making a barrier from attacking Mobs. It looks like, as with humankind, the earliest ChaosCraft NPCs are destined to live in caves.
The real power in this will be when I give them the ability to communicate and they start working together. Perhaps they will evolve to protect their children or to trade with each other creating a small economy.
The end goal is to see what NPC behaviors look like after a couple of thousands of generations of evolution. I am hoping to let it run for a while then one day come in and see some type of space-age Taj Mahal built with a small civilization of NPCs going about their daily life, interacting with each other in unexpected ways. Fortunately, the commands do not exist for these NPCs to reach singularity, similar to the hosts of West World.
Longer term, I am interested to see how this type of technology can be applied to the gaming industry in general. Imagine games that never get old because you never know what the NPCs behavior will be – completely fresh organic gameplay every time.
This post was written by Matt Lea. He is a web developer, Owner, and Chief Executive Officer of Schematical Consulting, a technical consulting firm focusing on Amazon Web Services, based in Madison, Wisconsin. Matt has a passion for education, sharing his knowledge from both business and gymnastics coaching in his book “Hacking Fear” and podcast “Ship Or Get Off The Pot.”