visit
Training a neural network to perform XOR is basically the Hello World of machine learning, and since Pixlings (agents) in my evolution simulator all have neural networks for brains, I figured it should be pretty straightforward implement it in my game. This blog post will show you how to do it (don’t worry, it’s really easy). If you want to follow along you can create an account at , it’s free and runs completely in the browser so no need to install anything. You can also see a finished version of this .
The general outline of what we’ll do is that we will give each Pixling an XOR “problem” each step, and if they solve the problem we will reward them by letting them reproduce. If they answer incorrectly we will kill them. This gives them plenty of incentive to get really good at XOR really quickly.This is the configuration we’re going for. You can check that it’s working by hitting run in the panel to the right. Duplicate this environment so you have two inputs to the network. You can duplicate it by right clicking the little square next to its name in the sidebar to the left and choosing “Duplicate” (surprise surprise). Hit Update to save these changes.
If the Pixlings use this ability in the correct situation (when they’re on a cell where A != B) they’ll be rewarded by getting to Reproduce. If they use the ability in the wrong situation they die though. Duplicate the ability to create the “False” ability, except for that one the comparison should be == instead of !=. Almost done! Next we just need to create a new Pixling that we can use to clone into the world. Go to the “Pixling zoo” tab and add a new Pixling. Set its abilities to the two abilities you just created. We also want our world a bit larger than the default so change it to at least 300x300 in the Advanced tab. Hit Update to write your changes to your world.
Use this button to spawn new Pixlings. Initially they have completely random weights so chances are they’ll die pretty quickly. If you spawn a bunch you should get some that perform ok at least though, and fairly quickly you’ll have a world full of Pixlings, like this:
Pixlings are colored to make it easier to see which “species” they belong to. Each time they reproduce their color is slightly changed, so you can easily see which ones are closely related and not. Video of this here: But it’s not filling up. Why? Well turns out we have a very basic problem with our world. The default neural networks only have one layer and we need at least two to perform XOR. Hit the edit world button again and browse to the Pixling zoo tab, where you can change the brainNLayers setting to two. Run it a while longer and you should end up with something that looks like this:
Much better. Video here: I.e. virtually no space left in the world. Which means the Pixlings are pretty great at performing XOR! (Remember, they are punished with death if they get it wrong even once, so they have a lot of incentives to be good at it). And that’s it, if you’ve followed along you should now have your own species of XORing Pixlings!
Finally, this was just one small, and fairly technical, demo of what you can build in Pixling World. But there’s a lot more you can do with this. You can create anything from to or . It’s up to you! To learn more you can read about how I’m implementing it, or check out the .
Hope you enjoyed! /Fredrik