DarwinBotsManual
Open the app EspañolES

.shang

The angle the shot that hit you came from, measured from your front toward the right: write it to .aimdx and you end up facing the shooter.

Facts

Address
209
Name
.shang
Kind
Sense: the engine writes it for the DNA to read
Group
Shots
Written by
The engine, in the shots phase, when one hits you: the angle it came from, measured from your front toward the right. You read it in the next cycle.
Cleared
The engine, every cycle, when the senses are cleared.
Range
0 to 1256 (one full turn): 314 is the right, 628 behind, 942 the left; straight ahead, close to 0 or to 1256.
Mutations
picked as a read (*)

.shang tells you where the last shot that hit you came from, as an angle between 0 and 1256 measured from your front and turning toward the right: 314 is from the right, 628 from behind and 942 from the left. A head-on hit gives a value near 0 or near 1256, depending on which side of center it arrives. Like .shflav, it arrives one cycle late, lasts one cycle and is 0 if nothing hit you.

Since it is measured in the same direction as .aimdx, copying it there makes you turn straight toward the shooter. This example only reacts to energy steals (.shflav −1); with *.shflav 0 != it would react to any hit:

cond
*.shflav -1 =
start
*.shang .aimdx store
stop

In the test, a bot that took a shot with .shang at 835 turned and in the next cycle already had the shooter in its .eye5.

To know whether there was a hit, don't look at .shang: a 0 or a very small value can mean “nothing hit me” or “I was hit head-on”. Look at .shflav, which is never 0 when there was a hit. If you only care about the side and not the exact angle, there are .shup, .shdn, .shdx and .shsx.