battlefield

battlefield preview image

1 collaborator

Default-person Dajun Yue (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 563 times • Downloaded 48 times • Run 0 times
Download the 'battlefield' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

turtles-own [ life attack enemy-insight enemy-around nearest-enemy attackee side]

to setup
  clear-all
  set-default-shape turtles "dot"
  let red-pos patches with [ pxcor < -10 and pxcor > -13 and pycor < 3 and pycor > -3 ]
  let blue-pos patches with [ pxcor < 30 and pxcor > 10 and pycor < 1 and pycor > -1 ]
  ask red-pos [
    sprout 1 [ 
      set color red 
      set size 2
      set heading 90 
      set side 15
    ]
  ]
  ask blue-pos [
    sprout 1 [ 
      set color blue 
      set size 2
      set heading -90 
      set side 105
    ]
  ]
  ask turtles [
    set life initial-life
    set attack preset-attack
    update-color
  ]
  reset-ticks
end 

to go
  if (not any? turtles with [side = 15]) or (not any? turtles with [side = 105]) [stop]  
  ask turtles [
    check-death
    update-color
    explore
    direct
    move
    target
    fight
  ]
  tick
end 

to explore
  search-enemy-insight
  if any? enemy-insight [
    set nearest-enemy min-one-of enemy-insight [distance myself]
  ]
  find-enemy-around
  if any? enemy-around [
    set attackee one-of enemy-around
  ]
end 

to direct
  ifelse any? enemy-around [
    face attackee
  ][
    ifelse any? enemy-insight [
      face nearest-enemy
    ][
      wiggle
    ]
  ]
end 

to wiggle
;  rt random 30
;  lt random 30
end 

to move
  
  if not any? turtles-on patch-ahead 1 [
    forward 1
    setxy pxcor pycor
  ]
end 

to target
  find-enemy-around
  if any? enemy-around [
    set attackee one-of enemy-around
  ]
end 

to fight
  if any? enemy-around [
    ask attackee [ set life life - [attack] of myself - (5 - random-float 10)]
  ]
end 

to search-enemy-insight
  set enemy-insight (turtles in-radius vision) with [ side != [side] of myself ]
end 

to find-enemy-around
  set enemy-around (turtles-on neighbors) with [ side != [side] of myself ]
end 

to check-death
  if life <= 0 [die]
end 

to update-color
  set color scale-color side (initial-life - life) (- initial-life) (2 * initial-life)
  set label (precision life 0)
end 

There is only one version of this model, created almost 11 years ago by Dajun Yue.

Attached files

File Type Description Last updated
battlefield.png preview Preview for 'battlefield' almost 11 years ago, by Dajun Yue Download

This model does not have any ancestors.

This model does not have any descendants.