Created
March 18, 2024 01:19
-
-
Save CodaBool/5fbed29002010c58007bd6f859e72703 to your computer and use it in GitHub Desktop.
netlogo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
globals [ | |
num_americans | |
num_british | |
] | |
breed [americans american] | |
breed [british britain] | |
;; you can define what variables are on a turle in two ways | |
;; 1. as a whole | |
turtles-own [ | |
energy | |
accuracy | |
attack_range | |
] | |
;; 2. as individual | |
;; american-Army [energy accuracy attack_range] | |
;; british-Army [energy accuracy attack_range] | |
to setup | |
clear-all | |
;; setup-patches | |
set num_americans 10 | |
set num_british 10 | |
setup_turtles | |
reset-ticks | |
end | |
to setup_turtles | |
create-americans num_americans [ | |
set energy 100 | |
set accuracy 30 | |
set attack_range 3 | |
set color sky | |
set shape "person" | |
setxy -10 + random-float 20 -12 | |
set heading 0 | |
] | |
create-british num_british [ | |
set energy 100 | |
set accuracy 30 | |
set attack_range 3 | |
set color sky | |
set shape "person" | |
setxy -10 + random-float 20 12 | |
set heading 0 | |
] | |
end | |
to go | |
if ticks > 264 [stop] | |
if (count americans = 0 and count british = 0 ) [stop] | |
interact | |
tick | |
end | |
to interact | |
ask turtles [ | |
if (breed = americans) [american_interact] | |
if (breed = british) [british_interact] | |
] | |
end | |
to american_interact | |
let enemy (turtle-set british) | |
let prey one-of enemy in-radius attack_range | |
ifelse prey != nobody [ | |
if random-float 100 < (energy / 100 * accuracy) [ | |
ask prey [die] | |
;; can track number dead here | |
;; set NUMBER-DEAD NUMBER-DEAD + 1 | |
] | |
][ | |
if any? enemy [face one-of enemy] | |
fd 1 | |
] | |
end | |
to british_interact | |
let enemy (turtle-set americans) | |
let prey one-of enemy in-radius attack_range | |
ifelse prey != nobody [ | |
if random-float 100 < (energy / 100 * accuracy) [ | |
ask prey [die] | |
;; can track number dead here | |
;; set NUMBER-DEAD NUMBER-DEAD + 1 | |
] | |
][ | |
if any? enemy [face one-of enemy] | |
fd 1 | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment