
Activity 2: Bullet
This example shows how you can add a new capability to the simulator. We are going to create a bullet capability. A bullet will be triggered from TRAP1 and TRAP6. These instructions will cause a bullet to be emitted in a particular direction.

Create a new strain profile called Uneatable. To make a strain uneatable, set the EAT Mode to be 8. Install the uneatable strain profile in slot 5.
Create a new strain profile called e_bullet. Configure it with the shoot3.kf seed file. Configure SPAWN-MODE to be 5 (so that this strain has the power to spawn new organisms of a different strain).
Make sure to protect all of this instruction: SPAWN (in the e_bullet strain).
Make sure to protect all code blocks up to 'evolve'.
A bullet is just another organism, but it is running a bullet program. This file is provided in the application resource folder ev5stuff. Make sure to use the file shoot3.kf.
; ; spawn3 - this version eats in the direction of motion until no more ; ; This creature uses SPAWN to make an uneat-able bullet ; out of itself to kill a creature. ; ; assumes SPAWN changed to not copy stacks ; ; STRAIN 5 should be un-eatble eat_mode -> 8 ; (x y energy strain cb -- rc) SPAWN ; ; SPAWN mode: set these bits (spawn_mode=46) ; bit 1 keep protected code blocks (optional) ; bit 2 can change strains ; bit 8 dont mutate ; bit 5 inherit "010" data stack items (2) ; main: { evolve call } _trap1: { } _trap2: { } _trap3: { } _trap4: { } _trap5: { } ; (x y -- rc) shoot _trap6: { DSLEN 54 >= ?exit 2dup 1 5 bullet SPAWN pop 2pop } _trap7: { } _trap8: { } _trap9: { } ; ; (x y -- ) ; go out ; bullet: { { 2dup OMOVE ?loop } call ; bullet move { 2dup EAT pop 2dup OMOVE pop ; ( x y -- x y rc) 255 NEAREST EAT ?loop } call HALT } ; --- protected / unprotected --- ; ; standard seed program ; evolve: { -1 0 trap6 reproduce call reproduce call ; ; go SOUTH-EAST until blocked (eat along the way) ; { 1 1 2dup eat pop omove ?loop } call reproduce call ; ; go WEST until blocked (eat along the way) ; { -1 0 2dup eat pop omove ?loop } call reproduce call ; ; go SOUTH-WEST until blocked (eat along the way) ; { -1 1 2dup eat pop omove ?loop } call reproduce call ; ; go EAST until blocked (eat along the way) ; { 1 0 2dup eat pop omove ?loop } call reproduce call ; ; go NORTH-EAST until blocked (eat along the way) ; { 1 -1 2dup eat pop omove ?loop } call reproduce call ; ; go SOUTH until blocked (eat along the way) ; { 0 1 2dup eat pop omove ?loop } call reproduce call ; ; go NORTH until blocked (eat along the way) ; { 0 -1 2dup eat pop omove ?loop } call reproduce call ; ; go NORTH-WEST until blocked (eat along the way) ; { -1 -1 2dup eat pop omove ?loop } call reproduce call ; ; do it all over again ; 1 ?loop } reproduce: { ; ; compute 1/4 of our energy, and store in R0 ; energy 4 / R0! ; ; Make 1st spore to the square on our left. ; -1 0 R0 make-spore pop ; ; Put 2nd spore at the same spot (fertilizing it) ; -1 0 R0 make-spore pop ; ; get the hell out of the way so we don't eat our own ; babies, or they don't eat us. ; 1 1 omove pop 0 -1 omove pop 0 -1 omove pop 0 -1 omove pop 0 -1 omove pop 0 -1 omove pop } |