Module: ant | ant.py | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A sample implementation of a unique finite state automaton with agents. The FSAs consist of ants, which are agents that move around on a two-dimensional automaton. Ants have a state, a location, and a direction. They also have two figures that determine how complex they are: the total number of possible states they can have, and the total number of colors that the ant can discern and manipulate; both of these figures must powers of two. Ants are deterministic creatures, whose behavior is deterministically determined by their genomes; these consists of three lookup tables, or genes: one for state, one for color, and one for action. Here, color refers to the cellular states of the underlying automaton (which do not spontaneously change). The total number of colors that an ant can interact with acts as a bitmask, called the color mask, on the underlying cell state; if an ant only can interact with 8 colors, then it can only retrieve and change the lower 3 bits of the state of each cell it is located on. The ant's state is an internal designation that modifies its behavior; the state is an integer between 0 and N - 1, where N is the total number of states. The lookup tables, or genes, are each used by the current perceived color and state, and thus are two dimensional arrays. Ants can also perform an action, which is one of the four possible behaviors: do nothing, turn left, turn right, or move forward (advance). Each update, an ant will do the following:
|