#side Adaptive 1.1 #author Matt Burkholder #date 10 March 2006 #color FFF #seed 2 4 1 1 3 4 1 #code #var Feed-Loop #var Feed-ID #var Feed-Time #var Feed-Prefer #var Feed-Type #var Food-Sensor-Time #var Read-Loop #var Last-Used #var First-Empty #var Food-Drift #var Stack-Watch #vector Feed-Position #vector My-Food Read-Requests: Stack Stack-Watch! 2 Feed-Loop! do Feed-Loop while time Feed-Time > Feed-Type Feed-Prefer < Feed-Loop Feed-Type > Feed-Loop messages and and or if 0 Feed-ID! -997 -997 Feed-Position! 0 Feed-Type! then do Feed-Loop messages while Feed-Loop receive 3 = if dup Feed-ID = if 0 Feed-ID! -998 -998 Feed-Position! 0 Feed-Type! then rrot dup 0 < if 2drop drop else 2dup position Feed-Position position dist syphon-range min in-range if Feed-Position! Feed-ID! time 100 + Feed-Time! Feed-Loop Feed-Type! else 2drop drop then then else stack dropn then Feed-Position Position v- rect-to-polar syphon-direction! syphon-distance! energy 2 > Feed-ID and syphon-max-rate negate 0 ifev syphon-rate! armor max-armor > max-repair-rate 0 ifev repair-rate! My-Food seek-location loop Feed-Type Feed-Prefer = ifr Feed-Loop 1 - Feed-Loop! loop Stack-Check^ return Scan-Food: Stack Stack-Watch! time Food-Sensor-Time < ifr time 100 + Food-Sensor-Time! 200 Last-Used! fire-food-sensor sync Food-Found if 196 Read-Loop! do Read-Loop 4 + dup Read-Loop! read dup time > if Read-Loop Last-Used! then while-loop do 0 Read-Loop write Read-Loop 4 - Read-Loop! Read-Loop Last-Used > while-loop do Idle^ 0 First-Empty! 196 Read-Loop! do Read-Loop 4 + dup Read-Loop! read dup time > if Read-Loop 2 + vread food-position 0.5 in-range if drop Read-Loop First-Empty! Food-Listed& jump then else First-Empty nif Read-Loop First-Empty! then then while-loop Food-Listed: food-energy 10 * food-sensor-time + First-Empty write food-position First-Empty 2 + vwrite next-food while-loop ;food-found 996 read - 2 / Food-Drift + Food-Drift! Last-Used 200 - 5 / 996 read - 2 / Food-Drift + Food-Drift! Food-Drift 3 > if 996 read 1 + 6 2 type-population * 2 4 type-population * + min 996 write 0 Food-Drift! then Food-Drift -3 < if 996 read 1 - 3 max 996 write 0 Food-Drift! then then Stack-Check^ return Stack-Check: Stack Stack-Watch > if Stack print pause then return #type Feeder #color 00F #decoration 000 x #hardware processor 40 eater 1.0 energy 250 50 armor 50 engine 0.04 syphon 1.0 20 radio send receive read write #code #var Read-Loop #var Best-Address #var Best-Distance #var My-Address #var Chirp-TIme #var Last-Armor #vector Home #vector Best-Food do time id 5 * < while-loop 998 vread Home! 2 Feed-Prefer! position My-Food! Read-Food^ Run-Loop: Idle^ energy 140 > if Feed-Position Position v- rect-to-polar syphon-direction! syphon-distance! syphon-max-rate negate syphon-rate! else energy 25 < if syphon-max-rate 2 / syphon-rate! Feed-Position Position v- rect-to-polar syphon-direction! syphon-distance! else 0 syphon-rate! then then My-Food position radius in-range if eaten if Read-Food^ else my-Address if 1 My-Address 1 - write then Best-Address if sync Best-Address read time < if time 50 + Best-Address write Best-Address My-Address! Best-Food My-Food! else 0 My-Address! Read-Food^ then else 0 My-Address! Read-Food^ then then else My-Food 2dup or if seek-location else 2drop then Read-Requests^ then Run-Loop& jump Idle: time Chirp-Time > My-Address and if time 50 + My-Address write time 25 + Chirp-Time! then 998 vread Home! armor max-armor > max-repair-rate 0 ifev repair-rate! armor last-armor < if feed-position 0 > swap 0 > and if Position feed-position v- 0.1 vs* feed-position v+ 8 restrict-position My-Food! else Position home v- 0.1 vs* home v+ 8 restrict-position My-Food! then position -2 3 3 send then armor last-armor! enemy-collision if position -1 3 3 send then return Read-Food: stack Stack-Watch! 200 Best-Distance! 0 Best-Address! 196 Read-Loop! do My-Food seek-location Read-Loop 4 + dup Read-Loop! read dup time > if Read-Loop 1 + read time < if Read-Loop 2 + vread 2dup 2dup 2dup 2dup or if ;home dist dup Best-Distance < if ;home dist rrot position dist + dup Best-Distance < if Feed-Position dist rrot position dist + rrot home dist + dup Best-Distance < if Best-Distance! Best-Food! Read-Loop 1 + Best-Address! else drop 2drop then else 2drop 2drop 2drop then then then while-loop Read-Requests^ Stack-Check^ return #type Builder #color F0F #decoration 000 x #hardware processor 20 energy 200 5 engine 0.02 solar-cells 0.1 armor 200 repair-rate 0.05 constructor 5 food-sensor 9 6 robot-sensor 9 radio send receive read write #code #var Chirp-Time #var Fighter-Ratio #var Food-Ratio #var Build-Ratio #var Defenders #var Solars #var Builders #var Feeders #var Controlers #var Builder-Spacing #var Wall-Spacing #var Space-Factor #var Building-Rounds #var No-Building #vector Chirp-Position #vector dest #const Limit 2000 Food-Sensor-range 2 sqrt * Builder-Spacing! Food-Sensor-range 2 sqrt * 2 / 10 max Wall-Spacing! Builder-Spacing -3 / Space-Factor! do speed sync while-loop Position dest! Main-Loop: Idle^ Listen-To-Requests^ energy food-sensor-firing-cost > time food-sensor-time > and Scan-Food& ifc 50 periodic-robot-sensor Scan-Robots& ifc constructor-type nif 0 constructor-rate! 2.5 4 type-population 997 read 1 max / 1.75 * - time 36000 / + Fighter-Ratio! ;changed 2.5 to 3.5 996 read Food-Ratio! 994 read 995 read 1 max / Build-Ratio! 4 type-population Defenders! 3 type-population Solars! 2 type-population Builders! 1 type-population Feeders! ;1 type-population Controlers! Defenders Builders 1 - Feeders 0.25 * + Fighter-Ratio 0.5 max * < 4 Feeders Solars 0.30 * + ;energy available Builders constructor-max-rate * Build-Ratio / > 2 ;constructor available Feeders Food-Ratio > 3 1 ifev ifev ifev constructor-type! then Main-loop& jump Scan-Robots: robot-found nifr robot-shield-fraction 0.8 < ifr robot-position robot-id 3 3 send return Listen-To-Requests: do 1 messages while 1 receive 3 = if id <> if dest v- rect-to-polar swap dup Builder-Spacing < if Space-Factor swap / swap polar-to-rect Dest v+ Wall-Spacing Restrict-Position Dest! else 2drop then else 2drop then else stack dropn then loop return Idle: energy 100 < Chirp-Time 18000 = and position Chirp-Position dist radius 0.7 * > or if 1 Chirp-Time! else energy 180 > chirp-time 18000 < and if -999 -999 ID 3 1 send 18000 Chirp-Time! then then time Chirp-Time > speed not and if position ID 3 1 send time 50 + Chirp-Time! position Chirp-Position! 994 read Building-Rounds + 994 write 0 Building-Rounds! 995 read No-Building + Building-Rounds + 995 write 0 No-Building! ID 1 = if position 998 vwrite then then energy 25 > constructor-progress 10 > position dest 3 in-range or and if constructor-max-rate constructor-rate! ;994 read 1.1 + 994 write Building-Rounds 1 + Building-Rounds! else 0 constructor-rate! No-Building 1 + No-Building! then 995 dup Limit > if 10 / 995 write 994 read 10 / 994 write else drop then armor max-armor > max-repair-rate 0 ifev repair-rate! constructor-progress 10 <= if dest seek-Location else 0 engine-power! then return #type Solar #color FF0 #decoration 000 x #hardware processor 15 energy 100 0 solar-cells 0.35 armor 50 repair-rate 0.05 syphon 0.5 15 radio send receive read write #code #var Feed-ID #var Feed-Dist #var Feed-Loop 9999 Feed-Dist! 2 Feed-Prefer! Run-Loop: Feed-Position Position v- rect-to-polar syphon-direction! syphon-distance! energy 2 > syphon-max-rate negate 0 ifev syphon-rate! armor max-armor > max-repair-rate 0 ifev repair-rate! 3 type-population 5 > -1 2 ifev Feed-Prefer! Read-Requests^ Run-loop& jump Idle: return ;Fighter type #type Defense #color 059 #decoration 000 x #hardware processor 50 energy 500 50 armor 300 engine 0.07 repair-rate 0.1 robot-sensor 9 6 food-sensor 9 2 blaster 20 7.5 10 force-field 0.07 10 radio send receive read write #code #var Chirp-Time #var No-Shots #var Robot-Read #var target-ID #var target-dist #var shot-firing-delay #var shot-blocked #var Last-Armor #var Pivot-Distance #var sweep-range #var safe-time #vector Home #vector Center #vector target #vector target-velocity #vector Chirp-position #vector blocker #vector Pivot #vector Dest World-Width 2 / World-Height 2 / Center! do home or until 998 vread Home! sync loop 997 read 1 + 997 write Run-Loop: 998 vread Home! energy 400 < Chirp-Time 18000 = and if 1 Chirp-time! else energy 490 > Chirp-Time 18000 < and if -999 -999 ID 3 2 send 18000 Chirp-Time! then then energy 300 > energy 100 > Armor Last-Armor < and or 3 messages and if do 3 messages while 9999 target-dist! 3 receive 3 = if rrot 2dup position target-dist in-range if target! target-ID! else drop 2drop then else stack dropn then loop Start-Seek^ 0 force-field-power! 0 robot-sensor-focus-distance! 0 robot-sensor-sees-friends! 3 clear-messages time safe-time! else Armor Last-Armor! 3 clear-messages then energy 100 > if 30 periodic-robot-sensor if robot-found if robot-shield-fraction 0.9 > if robot-position robot-id 3 3 send Attack^ 0 force-field-power! 0 robot-sensor-focus-distance! 0 robot-sensor-sees-friends! 3 clear-messages time safe-time! then then then then energy food-sensor-firing-cost 10 * > time food-sensor-time > and Position Pivot 30 in-range and Scan-Food& Idle& ifec Listen-To-Requests^ Pivot-Movement^ Run-loop& jump Listen-To-Requests: pivot position dist Pivot-Distance! do 1 messages while 1 receive 3 = if id <> if 2dup position dist dup Pivot-Distance < if Pivot-Distance! Pivot! else drop 2drop then else 2drop then else stack dropn then Pivot-Movement^ loop return Pivot-Movement: Pivot or nifr position pivot 30 in-range if time safe-time - 80 / 12.5 + 25 min sweep-range! Pivot Position v- rect-to-polar swap ;magnitude on top sweep-range - sweep-range / pi * + 3 swap polar-to-rect position v+ 2.5 restrict-position Dest! Chirp-Time Time-Limit = Last-Used 200 = or energy 15 > and if Dest seek-location engine-power 4 / engine-power! else 0 engine-power! then else energy 2.5 < if pivot seek-location else 0 engine-power! then then return Idle: time Chirp-Time > position Chirp-position radius in-range not or speed not and if position ID 3 2 send time 50 + Chirp-Time! position Chirp-position! then Repair^ return Start-Seek: -999 -999 ID 3 2 send 18000 Chirp-Time! Seek: target seek-location ;position target position v- angle set-force-field 10 periodic-robot-sensor if robot-found if robot-shield-fraction 0.8 > Attack& ifg then then target position 1 in-range energy 50 < or ifr 3 receive if do target-id = if target! then stack while-loop then Seek& jump Attack: 0 shot-firing-delay! 0 No-Shots! 1 robot-sensor-sees-friends! do blaster-cooldown shot-firing-delay <= if robot-distance 2 / robot-sensor-focus-distance! robot-direction robot-sensor-focus-direction! 0 shot-blocked! fire-robot-sensor sync robot-found nifr do robot-side side = See-Friend& See-Enemy& ifec while-loop then target target-velocity seek-moving-location Repair^ energy 50 < No-Shots 5 > or until-loop Return See-Friend: shot-blocked nif robot-distance Shot-Blocked! robot-position blocker! then Next-Robot dup nif rdrop drop then return See-Enemy: robot-shield-fraction 0.90 > Fire-Shot& ifg Check-Next-Bot: Current-Robot-result 1 = No-Shots + No-Shots! Next-Robot return Pick-Target: shot-blocked Safe& ifg Fire-Shot: robot-side 20 min 10 * robot-type - robot-read! robot-reloading if 1 robot-read write then robot-read read robot-bomb or if Safe-Shot^ robot-position pivot 18 in-range if robot-position 2dup pivot v- angle set-force-field 7.0 Shot-Blocked min Shot-Blocked! else robot-distance 7.0 < if robot-position 2dup position v- angle set-force-field else robot-distance 9 > if robot-position position robot-position v- angle set-force-field else 0 force-field-power! then then 7.0 Shot-Blocked min Shot-Blocked! then else robot-position pivot 18 in-range robot-position pivot v- robot-velocity dot 0 >= or if Safe-Shot^ robot-position position robot-position v- angle set-force-field 1 Shot-Blocked min Shot-Blocked! else robot-position pivot robot-position v- angle set-force-field Shot-Blocked dup 4 ifev Shot-Blocked! then then position robot-position v- unitize Shot-Blocked vs* robot-position v+ target! robot-velocity target-velocity! 0 No-Shots! 0 return Safe: position robot-position v- unitize robot-distance shot-blocked - vs* robot-position v+ target! robot-velocity target-velocity! robot-side 20 min 10 * robot-type - robot-read! robot-reloading if 1 robot-read write then 0 return Safe-Shot: Shot-Blocked nif robot-position robot-velocity lead-blaster time robot-sensor-time - shot-firing-delay! 6.5 Shot-Blocked! else robot-distance shot-blocked - Shot-Blocked! then return Repair: armor max-armor < energy 30 > and max-repair-rate 0 ifev repair-rate! return #end