Author Topic: Tracker, 10 points  (Read 5043 times)

jedislight

  • Administrator
  • Newbie
  • *****
  • Posts: 4
    • View Profile
Tracker, 10 points
« on: March 30, 2012, 06:03:45 PM »
full featured track and circle bot I created while testing usability changes in 0.8

Code: [Select]
#author:jedislight
armor:1 #10
energy:2 #15
shields:2 #10
cpu:3 # 20 (10/fork)
radar:on
scanner:on
instructions:

10 maxshield store
10 maxarmor store
15 maxenergy store
.75 baseShieldPriority store
7.50 minShotEnergy store # 50% of max energy
3.75 motionReserve store # 25% of max energy
motionReserve .50 mul speed store # 50% of reserve (in case of 180)
east west add 2 div wanderTargetX store
north south add 2 div wanderTargetY store
east west sub boardSizeX store
south north sub boardSizeY store
1 targetX store
1 targetY store
-1 strafeXmod store
1 strafeYmod store
radarbots

defenseLoop offenseLoop fork

#fork
defenseLoop:
   #adjust shield based on energy priorities and armor level
   maxshield curshield sub fullShieldCost store
   baseShieldPriority maxarmor armor div sub currentShieldPriority store # currentShieldPriority = baseShieldPriority - armor/maxarmor
   energy currentShieldPriority mul energyMinimum store
   energy energyMinimum sub 0 max fullShieldCost min shield
   
   strafe wander
      radar
      ifelsegoto
   
   wander:
      #close to wander target? change it
      wanderTargetX x sub 2 pow wanderTargetY y sub 2 pow add .5 pow distance store
     
      newWanderTarget moveToWanderTarget
         distance 64 <
         ifelsegoto
         
      moveToWanderTarget:
         wanderTargetX x sub distance div toX store
         wanderTargetY y sub distance div toY store

         
         move motionReserve lockUntilEnergy goto
         
         move:
            toX motionReserve mul xvel
            toY motionReserve mul yvel
            defenseLoop goto
           
           
      newWanderTarget:
         0 xvel 0 yvel
         boardSizeX rand west add wanderTargetX store
         boardSizeY rand north add wanderTargetY store
         wanderTargetX x sub 2 pow wanderTargetY y sub 2 pow add .5 pow distance store
               
         newWanderTarget
            distance 64 <
            ifgoto
         wander goto
   
   strafe:
      #dir swap mul one by -1 go!
      targetX x sub 2 pow targetY y sub 2 pow add .5 pow distance store
     
      targetX x sub distance div toX store
      targetY y sub distance div toY store
     
      strafeMove motionReserve lockUntilEnergy goto
         
      strafeMove:
         strafeMoveContinue#stack callback param
         swapStrafe
            south y sub 64 < yv 0 > and
            y north sub 64 < yv 0 < and
            east x sub 64 < xv 0 > and
            x west sub 64 < xv 0 < and
            or or or
            ifgoto
         drop#drop paramater if not called
         
         strafeMoveContinue:
            toX strafeXmod mul speed mul yCircle store
            toY strafeYmod mul xCircle store
            strafeFinalMove #stack callback

            approach
               distance 225 >
               ifgoto

            fade
               distance 175 <
               ifgoto

            maintain goto

            approach:
               yCircle toY add 2 div yFinal store
               xCircle toX add 2 div xFinal store
               goto

            fade:
               yCircle toY sub 2 div yFinal store
               xCircle toX sub 2 div xFinal store
               goto 

            maintain:
               yCircle yFinal store
               xCircle xFinal store
               goto

            strafeFinalMove:   
               xFinal speed mul xvel
               yFinal speed mul yvel
         
      defenseLoop goto


#fork
#track enemy and set target location vars
offenseLoop:
   45 facing add face
   trackLoop offenseLoop
      radar
      ifelsegoto

trackLoop:
   offenseLoop
      radar not
      ifgoto
   radar 12 div dFactor store
   x scanset
   scan targetX store
   xv scanset
   scan targetXv store
   targetX targetXv dFactor mul add targetX store

   y scanset
   scan targetY store
   yv scanset
   scan targetYv store
   targetY targetYv dFactor mul add targetY store

   x targetX sub lookx store
   y targetY sub looky store

   lookx lookx mul looky looky mul add .5 pow T store
   looky T div normlooky store
   lookx T div normlookx store

   nonvertical vertical
      normlookx
      ifelsegoto
   
nonvertical:
   normlooky normlookx div arctan deg #raw aim(always to right)
   180 x targetX > mul add #reverse(+180) for targets to left, none (+0) for targets to right
   aim
   0 face
   firelabel goto

vertical:
   y targetY > 180 mul 90 add
   aim
   0 face
   firelabel goto

firelabel:
   energy motionReserve sub availableEnergy store
   shot trackLoop
      minShotEnergy availableEnergy < T 250 < and
      ifelsegoto

shot:
   availableEnergy 5 div shotPower store
   shotPower fire
   aiming center store
   center 1 add aim
   shotPower fire
   center -1 add aim
   shotPower fire
   center 2 add aim
   shotPower fire
   center -2 add aim
   shotPower fire
   center aim
   trackLoop goto
   
   
lockUntilEnergy:#(callback energy)
   energyTarget store
   lock:
   lock
      energy energyTarget <
      ifgoto
   goto #return
   
   
swapStrafe:#(callback)
   strafeXmod temp store # save x
   strafeYmod strafeXmod store # y -> x
   temp strafeYmod store # x -> y
   goto #return