-
Notifications
You must be signed in to change notification settings - Fork 9
Genetics
Genetics can be used to evolve a robot instead of manually programming them. This process involves a Genetic Algorithm (GA) used to generate random robots, evaluate their fitness by scoring them, and advance generations of the "gene pool" within the simulation.
Within the Sandbox go to Tools => Genetics or press G and it will open the genetic parameters window. There are many parameters and you can hover your mouse over them for a basic idea of how they work. You can leave the default parameters and press Start to begin evolving.
Once you have started the genetic simulation you will see a small pink cross on the map where your robot was located when the process began. This is called a "Spawn" and used to keep track of all the simulations you are providing to your robot. You can add additional spawns (in the same or other worlds) by right clicking on the map or using the Spawn Manager. The more scenarios you expose your robot to the better chance it has of developing successful strategies, but each scenario increases the simulation time.
After a short while you should see the score increase for your "Best" robot in the gene pool. This means it has done something like moving more tiles, collecting more gold, etc. based on the parameters you gave. At anytime you can go to the menu Genetics => Flash Best which will load the currently best evolved program into your sandbox robot and the debugger.
-
Random tests: In addition to the spawns you set (in the
Spawn manager), the robot is tested in this many random worlds. -
Orientations: In each world, the robot is tested this many times, facing a different direction each time.
-
Frames: The simulation of the robot stops after this many frames. Note that it can end earlier if the robot dies or violates some other constraints (see below).
The genetic algorithm tries to find the robot with the highest score, so you should set these parameters in a way that robots get higher scores when they do what you would want them to do (and lower scores if they don't!). For example, if you set the exploration reward very high and the gold reward very low, it's likely that the best programs will completely ignore gold.
-
Gold Reward: How much score the robot gains by picking up a pile of gold.
-
Battery Reward: How much score the robot gains by picking up a battery item.
-
Explore Reward: How much score the robot gains by visiting a new tile.
-
Collide Penalty: How much score the robot loses for touching a wall.
-
Early Reward: The score gained by the actions above is made dependent on how early in the simulation they happened.
These constraints can help speed up the genetic algorithm by ending simulations early if the robot is deemed non-functional according to certain criteria. Note that the constraints with numeric values are disabled by setting them to zero.
-
Idle Timeout: The simulation is ended prematurely if the robot has not moved for this many frames.
-
Idle IO Timeout: The simulation is ended prematurely if the robot has not issued an IO command for this many frames.
-
Force Stack: The simulation is ended prematurely if the stack pointer ever leaves the range of 0 to this value. This criterion forces the robots to work in a way humans would write programs (i.e. use the stack to temporarily store things).
-
Force IO: The simulation is ended prematurely if the robot ever issues an IO command that doesn't exist.
Each time you press Start you are seeding your gene pool with random programs. Anytime you wish you can "pin" your current best program using the Genetics => Pin Best menu. This will force the current best program to be part of the future genetic simulations. Pinning can be used for things as simple as ensuring your gene pool isn't lost when retraining to complex methods of cross-breeding.