The Brain of a Bot - GhengopelALPHA/scriptbots GitHub Wiki

The core of this sim is the behavior of the bots and how these behaviors interact and potentially evolve. The mastermind behind each bots actions is the Brain, a set of inputs, a set of outputs, and a set of Boxes, which all work together in the MLPBrain system. The details of these parts follow.

Video describing early brain mechanics, via Andrej Karpathy

Every bot has 23 inputs, 12 outputs, and 200 boxes, each with 5 connections to other boxes

INPUT DETAILS

Every agent has input sensors that range from [0,1] and are fed directly to the first brain boxes:

  • 6 Eyes, each with a Red, Green, and Blue sensor and pointing in custom directions with custom field of views. These eyes directly detect the RGB color of other bots based on proximity, direction, and containment in the field of view.
  • Health sensor, which reports the percent health the bot has.
  • Random sensor, is a value that gets random normal treatment every couple of ticks
  • Clock sensors, 1, 2, and 3. Absolute value of sine of current modcounter functions, basically produce a bump function over time, with 1 and 2 having constant frequency, and 3 having a frequency determined by an output
  • 2 Ears, each with a sound sensor, which reports volume of sound within the agent's hearing range. If the hearing range includes 0.25, the ear also hears a "rumble" of other agent's wheels (old sound and hearing sensors merged)
  • Smell sensor, which reports the number of other agents around this agent
  • Blood sensor, which reports the inverse of the health of the bots in front of this one.
  • Temperature sensor, reports exactly what the value of temperature is at bot's location (may change to discomfort in the future)
  • Player sensor, activated by pressing spacebar while agent is selected.
  • Cell smell sensors, fruit, meat, hazard, and water. Counts the amount of respective quantity in a range of cells around the agent, and reports the ratio of the current to the maximum possible.

(Excellent display of mid-tone-emitting bots (green waves) and high-pitched bots (blue waves))

OUTPUT DETAILS

Every agent has actuators ranging from [0,1] that are taken directly from the last brain boxes:

  • Left and Right Wheel positive speeds and negative speeds.
  • Boost, doubles agent speed, but also their health loss due to wheels and age.
  • Jump, when shifting from low values to high, triggers jump, which disables the agent's turning, prevents the agent from taking spike damage, and allows it to fly over other agents without bumping into them.
  • Red, Green, and Blue colors to display on itself (these are damped in the final result)
  • Volume and Tone, volume effects how far it can be heard, tone emits between [0,1] for hearing ranges to pick up.
  • Give, which determines if bot is willing to share its health with others who are in need. Triggers above 0.5.
  • Spike length, which can be used to severely damage other bots, perhaps killing them for meat food.
  • Jaw position, when shifting from low to high, triggers bite, a damaging effect to any other bots that happen to be in front.
  • Grab, forces another agent to stay close to the grabber. Activates above 0.5
  • Project, allows other agents to sexual reproduce with this agent, active above 0.5
  • Stimulant, improves brain weights based on degree of equality
  • Clock 3 frequency, sets the frequency for the third input clock.

(Sample of a clock's output over time, the abs(sin(x)) function)

BRAIN DETAILS

Every agent also has 150 (settings.h adjustable) internal variables ranging from [0,1] that can be thought of as neurons, called boxes. Each box has 5 (again adjustable) connections to other boxes. Each box has the following attributes:

  • Bias: The initial value of the sum input counter (SIC). Ranges from [-1,1].
  • Global Weight (gw): A multiplier times the final SIC value before it gets converted through a sigmoid for the final value.
  • Dampening (kp): Multiplier times the difference of a box's actual value and it's target, the result of which gets added to the box's actual value. Effectively delays signals.
  • Connection Weight (w): Strength of a connection's contribution to the SIC.
  • Connection ID (id): Box reference ID of the source of the given connection.
  • Connection Type (type): one of three types: 0, regular OR input; 1, change-sensitive connection (instead retrieves difference between reference box's old output and actual output); 2, sticky, memory synapse (if source box is > 0.5, the rest of this whole box is skipped, effectively freezing the value).

This entire process is run through once every world tick, and is by far the most processor intensive element of the Scriptbots program. It's necessary, however, as we are attempting to reproduce complex behaviors using these simple yet powerful Brains.