#side Rat #author Warren (Based on Devon's rabbit) #date 4 March 2002 A food-eater with flash-shielding. Reproduces slowly but survives under heavy fire. #color 880 #type Rat #color 810 #hardware energy 400 70 ; c 110 food-sensor 12 25 ;c ~30 engine .05 ;c 50 processor 15 ;c 45 solar-cells 0.01 ;c 18 armor 120 ;cost 1.0/armor eater 1.5 ;c 90 constructor 1.0 ;c 120 repair-rate .2 ;c 20 shield 0.5 ;c 150 shot-sensor 7 1 ;low radius, low cost robot-sensor 5.5 1 grenades 5 5 5 #code ;; steering code ;; #var dest-x #var dest-y #var destination? 0 #var next-shot-sense -1 ;time of next shot-sensor firing set-destination: ; x y -- dest-y! dest-x! 1 destination?! return ;;; main ;;; #start do food-sensor-cooldown not seek& ifc energy constructor-remaining 250 min > if ;reproduce if lots of energy available or if ;we expect to live long enough to give birth and have enough energy to do so 1 constructor-type! constructor-max-rate constructor-rate! else 0 constructor-rate! then energy 20 > if ;;don't defend if too low on energy time next-shot-sense > if 0 0 fire-shot-sensor 0 0 fire-robot-sensor sync time 5 + next-shot-sense! then robot-found grenades-cooldown not and energy 150 > and if robot-position robot-velocity velocity v- robot-distance grenades-speed / vs* v+ position v- rect-to-polar fire-grenade then ;Raise shields if shots were seen ;raise shields more if we are low on armor max-armor armor - 0.002 * 0.1 + ;full armor ==> 0.1, ;50 armor gone ==> 0.2, etc shot-found robot-found + 2 min * max-shield min shield! ;this should be based on log of aggregate damage seen energy armor 50 min > max-armor 1 - armor > and if max-repair-rate repair-rate! else 0 repair-rate! then else 0 repair-rate! 0 shield! then destination? if dest-x dest-y seek-location then ;else is handled by seek reutine forever seek: food-found if ;hack so that at birth we spread out 0 0 fire-food-sensor else food-sensor-range random-angle fire-food-sensor then sync food-found if food-position set-destination else ;wander, at reduced power. 0 destination?! engine-max-power 0.5 * engine-power! 0.1 speed if velocity angle else random-angle then polar-to-rect set-velocity then return #end