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
;; built for Netlogo version 6.04 | |
;; a small demo model that loads a map | |
;; populates it with golems, and gives one of them | |
;; a message - or a virus, pick your metaphor - and turns | |
;; them loose. | |
;; Golems move by selecting a target patch of ground ahead of them within their cone of vision | |
;; where ground they can walk on is the colour of the path | |
;; in the maps generated by Oleg Dolya's Medieval Fantasy City Map Generator at | |
;; https://watabou.itch.io/medieval-fantasy-city-generator | |
;; 1. Generate a map there, and select the 'sanguine' colour palette (if you select a different palatte, you'll have to | |
;; figure out its colour value for the pcolor variable in the 'walk' procedure. | |
;; 2. Save that map to your computer in the same place you have this model. | |
;; In the INTERFACE: | |
;; 3. Create a button called '1. Load Map' and give it this code: | |
;; ca | |
;; import-pcolors user-file | |
;; 4. Create a button called '2. Setup Golems' and give it this code: | |
;; setup | |
;; 5. Create two sliders, one called 'loudness' the other called 'vision' and set their min value to 1 and max value to about 15. | |
;; 6. Create a 'go' button. Give it the command `go` and tick off the 'forever' box. | |
;; 7. Create a slider called | |
;; num-walkers | |
;; and make sure that the minimum is set to 2, and the 'value' (starting position of the slider) is at least 2 or more | |
;;---- | |
;; the model is built by combining default code snippets in netlogo: | |
;; network-import | |
;; communication t-t network example | |
;; link walking turtles | |
;; you can also build some monitors. For instance, right-click in the interface and select new monitor | |
;; then paste this code into it: | |
;; ((count walkers with [message?]) / (count walkers)) * 100 | |
;; this will tell you the percent of the population that has heard the message. | |
;; you could graph this by making a new plot, and giving it the same code | |
;; right-click, select plot, and in plot update commands paste the same code. | |
;; While the model is running, you could type `pd` in the observer box at the bottom of the interface. This will make the walkers draw on the map | |
;; where they've been. Maybe there's something particular about a city layout that draws walkers to particular places? | |
;; How else might you expand this? | |
;; globals | |
breed [walkers walker] ;; the turtles who wander around | |
walkers-own [ ;; variables that only the walkers own | |
message? | |
direction | |
] ;; new | |
;; setup | |
to setup | |
create-walkers num-walkers [ | |
set color blue | |
set shape "person" | |
set size 15 | |
setxy random-xcor random-ycor | |
if pcolor != 38.9 [die] ;;; drastic, but we don't want any walkers in the rivers or on the walls or inside buildings | |
set message? false ;; ignorance is bliss | |
] | |
ask one-of walkers [ set message? true ] | |
reset-ticks | |
end | |
to go | |
ask walkers [ | |
ifelse color = blue [walk][chase] | |
communicate ;;; they talk to anyone else who happens to be present | |
recolor ;;; change their color if they've encountered someone with the message | |
] | |
if ((count walkers with [message?]) / (count walkers)) * 100 > 95 [stop] ;;; ending condition | |
tick | |
end | |
to walk | |
ask walkers[ | |
rt random 30 - 15 | |
let target one-of patches in-cone 1.5 120 with [pcolor = 38.9] | |
if target != nobody [ | |
face target | |
move-to target | |
] | |
] | |
end | |
to chase | |
ask walkers [ | |
rt random 30 - 15 | |
let chasee one-of walkers in-cone vision 120 with [color = blue] | |
if chasee != nobody [ | |
face chasee | |
walk | |
] | |
] | |
end | |
to communicate ;; turtle procedure | |
if any? other walkers in-radius loudness with [message?] ;;shouting! | |
;; if any? other walkers-here with [message?] ;;; whispering? anybody here heard anything good? Comment out the line above, uncomment this one. What difference does it make? | |
[ set message? true ] ;;; if yes, then now I know the message too | |
end | |
to recolor ;; turtle procedure | |
ifelse message? | |
[ set color red ] | |
[ set color blue ] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment