Turtle Wars

Battlefield Simulators

Battlefield simulators and battlefield management systems (BMS) are important in computer games and also for planning and managing real battles. A real BMS is very complicated and uses top down methodologies for trying to predict the outcome of a battle. Unfortunately, there are too many variables to make this practical.

Turtle Wars: A bottom-up approach

Turtle Wars customizes the ABM framework. There are two armies: red turtles and blue. Each army wants to dominate patches with high strategic value.

A turtle behaves according to its strategy: attack, defend, flank, or retreat. An attacking turtle moves toward patches of high strategic value within its field of vision. It also shoots opponents within its field of vision. A defending turtle also shoots opponents within its field of vision; however it doesn't move; it stands its ground. A retreating turtle runs from the nearest opponent. Sometimes, if a turtle hasn't had enough training, it spontaneously retreats after it has been shot at a few times. Flanking isn't implemented yet, but the general idea is to go around the enemy and sneak up from behind.

A Demo

In this demo, all patches have strategic value 0 except those patches with distance to the origin <= 4. Those patches all have the same strategic value: 50 out of a possible 100. They are shaded green.

In this demo the blue army is defending the green patches and is deployed around the perimeter of this disk facing away from the origin. The red army is attacking. They are deployed along a line facing the origin:

As you can see, after 71 ticks the surviving members of the blue army are in retreat while the red army is occupying the green patches:

Why did the red army win?

Hints

In my implementation I define two procedures:

to shoot-foe

end

to get-shot [n-times]

end

The shoot-foe procedure forms a set of all turtles within the shooter's field of vision and having a different breed than the shooter. It picks one of these targets at random (if there are any and if the shooter has any ammo left). The shooter squeezes off n shots. In my simulation I chose n to be the minimum of 3 and ammo. Don't forget to deduct ammo by n. Depending on the accuracy, the shooter asks the target to get shot n times.

In get-shot the target deducts n from its armor. If its armor is <= 0, the target dies. Otherwise, if the armor is below (100 – training), the target sets its strategy to "retreat".

Deploying the red turtles is easy. Here's the procedure for deploying blue turtles:

to deploy-blue-turtles
   let angle 360 / init-num-blues
   foreach [self] of blue-turtles [
      ask ? [
         let x radius * cos (who * angle)
         let y radius * sin(who * angle)
         setxy x y
         face patch 0 0
         rt 180
      ]
   ]
end

Basically, this procedure uses trigonometry to deploy the blue turtles evenly around a circle with radius = 4, then asks them to face away from the center of the circle (which is the origin). Note that this is a global procedure, not a turtle procedure (method). That's why I had to ask the loop control variable, ?, which is a blue turtle, to execute the commands in the command block.

Note also that the blue turtles are properly deployed for an attack coming from an unknown direction, but the turtles at the far end of the circle react too late to help their comrades at the lower end of the circle to withstand the attack of the entire red army.