war-is-stupid


Information

Created with NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.



Procedures

NetLogo Version: NetLogo 4.0.4

; add model procedures here

breed [ soldiers ]


soldiers-own
[ health
  goal-head
  luck
]

to startup setup end 
 
 to setup
 ca 
 create-soldiers force * 2
 [ set color blue
   set xcor random world-width
   set ycor max-pycor - random (max-pycor * .5)
   set goal-head 180
   set heading goal-head
   set health 10
   set label health
   set luck 0
 ]
 ask n-of force soldiers
 [ set color red
   set xcor random world-width
   set ycor min-pycor + random (max-pycor * .5)
   set goal-head 0
   set heading goal-head
 ]

 set-current-plot-pen "red"
 plot count soldiers with [ color = red ]
 set-current-plot-pen "blue"
 plot count soldiers with [ color = blue ]
 display
 end
 
 to go
   ask soldiers
    [ let enemies soldiers in-radius-nowrap 2 with [ color != [color] of myself ] 
      let friends soldiers in-radius-nowrap 2 with [ color  = [color] of myself ]
      ifelse any? enemies
      [ ifelse count enemies <= count friends
        [ let enemy min-one-of enemies [ distance myself ]
          ifelse [ patch-here ] of enemy != patch-here
          [ charge enemy ]
          [ attack-enemy enemy  ]
        ]
        [ evade ]
      ]
      [ reconnoiter ]
    ]
    
    ask soldiers
    [ if health <= 0 [ die ]
      set label health
    ]
    tick
    set-current-plot-pen "red"
    plot count reds
    set-current-plot-pen "blue"
    plot count blues     
    ifelse not any? soldiers
    [ output-print "TOTAL MUTUAL ANNIHILATION!" stop
    ][
    ifelse not any? blues
    [ output-print "RED VICToRIOUS!" stop ]
    [ if not any? reds
      [ output-print "BLUE VICtORIOUS!" stop ]
    ]]
end

to-report reds
   report soldiers with [ color = red ]
end
   
to-report blues
   report soldiers with [ color = blue ]
end
        
to march  jump (.5 + random-float .5) end
to charge [ #someone ] face #someone march end
to evade  rt 180 + plus-or-minus 90 march end
to reconnoiter set heading goal-head + plus-or-minus 45 march end

to attack-enemy [ enemy ]
   ifelse random-float luck <= [ random-float luck] of enemy
   [ set health health - 1 
     set luck luck * .99
     ask enemy [ set luck luck * 1.01 ]
   ]
   [ ask enemy [ set health health - 1 set luck luck * .99]
     set luck luck * 1.01
   ]
   rt 90
   march
end

to-report plus-or-minus [ #angle ]
   report #angle - random-float ( 2 * #angle )
end   


                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download war-is-stupid --