-
Notifications
You must be signed in to change notification settings - Fork 2
/
reporters.nls
46 lines (40 loc) · 1.53 KB
/
reporters.nls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
;;;;;;;;;;;;;;;;;
;;; Reporters ;;;
;;;;;;;;;;;;;;;;;
;;reports the nearest turtle with a different allegiance
to-report closestHostile [thisTurtle]
let myAllegiance [allegiance] of thisTurtle
report min-one-of turtles with [allegiance != myAllegiance] [distance thisTurtle]
end
to-report closestAlly [thisTurtle]
let myAllegiance [allegiance] of thisTurtle
report min-one-of turtles with [allegiance = myAllegiance] [distance thisTurtle]
end
;;reports a string in NetLogo format created from a csv line
;;for instance would turn
;;" 10 , 9, 8, 6"
;;into
;;[ 10 9 8 6 ]
to-report csv-split [csvLine]
let index 0
set csvLine remove " " csvLine ;;eliminate whitespace
while [member? "," csvLine] ;;while there are still commas in the line
[
set index position "," csvLine ;;find the position of the comma
set csvLine replace-item index csvLine " " ;;replace the comma with a space
]
report (word "[ " csvLine " ]") ;;surround with brackets and return
end
to-report turtlesInRange [range thisTurtle]
report turtles with [distance thisTurtle < range]
end
to-report terrain-modifier [terrain]
if terrain = 0 [report 1]
if terrain = 1 [report forestMoveMod]
if terrain = 2 [report waterMoveMod]
end
to-report feet-to-patches [feet]
;;the map is 9,675 feet across
;;the model is 1215 patches across
report feet * (1215 / 9675)
end