#side Teledont This is almots a complete rewrite of Teledont. It now uses multiple sensor returns for food and robots. It selects the largest food to eat. It also tries to avoid friendly fire but this doesn't seem to work yet. (Warren 20021216) Now uses world-size. 1-15-03 Reduced cell size by about half, minor changes #author Matt Burkholder #date 22 Nov 2002 #color 55f #type Teledont #color a0a #hardware processor 25 engine 0.1 constructor 0.75 energy 1000 20 solar-cells .08 eater 2.25 robot-sensor 25 5 food-sensor 12 5 armor 302 repair-rate .15 blaster 7 25 4 #code #vector target #vector dest #vector Home #var Target-Direction 0 #var Target-Result 0 #var Target-Loop 0 #var Food-Good 0 #var robot-sensor-now 0 #var Take-a-Shot 0 #var Home-Factor 1 #var Dist-Factor 2 #vector Center #var Run-Min #var Run-Factor #var Shoot-Factor #const Gutter 20 center-x: world-width 2 / return center-y: world-height 2 / return center: center-x center-y return #start blaster-range 2 - Run-Min! 100 blaster-range / Shoot-Factor! 120 blaster-range / Run-Factor! do speed while-loop 1 robot-sensor-sees-friends! position center-y^ < gutter world-height gutter - ifev swap center-x^ < gutter world-width gutter - ifev swap Home! Home dest! food-sensor-range 0.25 * food-sensor-focus-distance! do energy 250 > energy constructor-remaining 1.25 * > or constructor-max-rate 0 ifev constructor-rate! 1 constructor-type! armor max-armor < energy 20 > and max-repair-rate 0 ifev repair-rate! Need-Food^ dup time robot-sensor-now > or if energy 20 > if fire-robot-sensor then dup Scan-Food& ifc sync Pick-Food& ifc robot-found if 0 Take-a-Shot! 0 Target-Loop! do Target-Loop current-robot-result! Do-I-Shoot-It^ if robot-position Target! current-robot-result Target-Result! Time Take-a-shot! Too-Close^ if -5 robot-Direction polar-to-rect position v+ dest! then do current-robot-result Take-a-Shot and while current-robot-result 1 - current-robot-result! In-the-Way^ if -5 Target-Direction polar-to-rect position v+ dest! 0 Take-a-shot! then loop Target-Result current-robot-result! then Target-Loop 1 + Target-Loop! Target-Loop num-robot-results < Take-a-Shot not and while-loop time 20 + robot-sensor-now! else time 100 + robot-sensor-now! 0 Take-a-Shot! then else drop Move-Home^ then Take-a-Shot Blaster-Cooldown 1 <= and Compute-and-Fire& ifc Motion^ forever Do-I-Shoot-It: robot-side side <> dup if Take-a-shot energy 500 > or robot-distance robot-mass Shoot-Factor / 12 max < or and then return Too-Close: robot-distance robot-mass Run-Factor / Run-Min min < armor 120 < or return In-the-Way: robot-side side = dup if ;target robot-position v- 2dup target project v- rect-to-polar Target-Direction! robot-position position v- 2dup target position v- project v- rect-to-polar Target-Direction! robot-radius 2.5 * < and then return Compute-and-Fire: robot-distance 5 < if robot-direction fire-blaster else robot-position position v- 2dup target! robot-velocity velocity v- robot-distance blaster-speed / time Take-a-Shot - + vs* v+ rect-to-polar swap Blaster-Range < if fire-blaster else drop then then return Need-Food: eaten engine-power or not friendly-collision or return Scan-Food: Home position v- angle food-sensor-focus-direction! fire-food-sensor return Pick-Food: 0 Food-Good! food-found if do food-energy food-position home dist Home-Factor * - food-distance Dist-Factor * - dup Food-Good > if Food-Good! food-position dest! robot-found if 0 Target-Loop! do Target-Loop current-robot-result! food-position robot-position food-distance 2 / in-range robot-side side = and if 0 Food-Good! then Target-Loop 1 + Target-Loop! Target-Loop num-robot-results < food-good and while-loop then else drop then next-food while-loop then Food-Good nif 10 Home Position 25 in-range random-angle food-sensor-focus-direction ifev polar-to-rect position v+ dest! then return Move-Home: 1 type-population 3 > Position Home 20 in-range and nifr Home center^ v- rect-to-polar 1.57 + polar-to-rect center^ v+ Home! return #const wall-avoid-dist 3 Motion: energy food-sensor-firing-cost > food-found or if dest wall-avoid-dist max world-height wall-avoid-dist - min swap wall-avoid-dist max world-width wall-avoid-dist - min swap seek-location else 0 engine-power! then return #end