Food Bot Genetic Algorithm

Current Generation

Food Eaten: 0

Statistics

Previous Generation: N/A

Best Fitness: N/A

N/A

Description

This simulation runs a genetic algorithm to determine the best set of 256 instructions for eating as much food as possible. There are 50 food bots that are initially generated with a completely random set of 256 instructions, and a volitility value which determines its rate of mutation during reproduction. Each food bot has a lifespan of 512 cycles. Each food bot also has a limited short term memory. It can remember two values, in the order of which was recorded most recently. It uses its sensor to find the closest food in its line of sight, forgetting its oldest memory in the process. Each cycle, the food bots execute one instruction. Refer to the next section for the definition of each instruction. The fitness of each bot is determined after every bot has died either from old age (finished 256 instructions) or from a genetic defect (instruction to jump to the end of the program). The fitness of each bot is equivalent to the proportion of food it's eaten to the total food eaten by that generation. After the generation completes its life cycle, it's decendants are born. Each new descendant is generated from two randomly selected parents. Each parent is more likely to be selected if it has a higher fitness. The mating cycle repeats until the number of decendants is equal to that of the previous generation. After each new descendant is generated, there is a chance some of its genes may mutate. In other words, some of its instructions are changed randomly. The rate of mutation is dependant on the child's level of volitility. Its volitility is determined by the weighted average of its parents', weighted by their fitness.

Instruction Definitions

TURN_L

This rotates the food bot's orientation 90° counterclockwise.

TURN_R

This rotates the food bot's orientation 90° clockwise.

MOVE_F

This moves the food bot forward by one cell in the direction it's facing, looping around the edges of the grid if necessary.

SENSE

This causes the food bot to forget its oldest memory and record a new one. It uses its sensor to determine the distance to the closest food in its direct line of sight.

LABEL

This will create a point in the code for the bot to jump to.

PREV_LT

This jumps to the closest label to the left of this instruction if the newest memory is less than the oldest (in terms of distance to the food it sensed).

NEXT_LT

This jumps to the closest label to the right of this instruction if the newest memory is less than the oldest (in terms of distance to the food it sensed).