-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.nls
142 lines (133 loc) · 4.23 KB
/
setup.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
;;include extensions
extensions [array]
;;create the types of turle
breed [unionRegiments unionRegiment] ;;union infantry regiments
breed [confederateRegiments confederateRegiment] ;;confederate infantry regiments
breed [unionArtilleryUnits unionArtilleryUnit] ;;union artillery units
breed [confederateArtilleryUnits confederateArtilleryUnit] ;;confederate artillery units
;;give the turtles their attributes
turtles-own [allegiance] ;;specifies union or confederate
;;give the patches their attributes
;;set globals
globals [initDir]
;;these four functions initialize each type of turtle from a csv file
;;the format of information about each turtle in the text file is
;;line[0] = xPos
;;line[1] = yPos
;;etc
;;initialize union regiments
to create-ui
file-open "SanitizedSetupFiles/unionInfantrySan.csv"
let soldierInfo []
let line " "
let splits " "
let xPos 0
let yPos 0
while [not file-at-end?] ;;iterate through each line of the csv
[
set line file-read-line
set splits csv-split(line) ;;encloses items in brackets and space seperates
set soldierInfo read-from-string splits ;;read into a list
set soldierInfo array:from-list soldierInfo ;;convert into an array
set xPos array:item soldierInfo 0
set yPos array:item soldierInfo 1
create-unionRegiments 10 ;;create a turtle from this line
[
setxy xPos yPos
set color blue
set shape "circle"
set size 5
set allegiance "Union"
]
set soldierInfo [] ;;reset information
]
file-close
end
;;initialize union artillery units. See create-ui comments for documentation
to create-ua
file-open "SanitizedSetupFiles/unionArtillerySan.csv"
let soldierInfo []
let line " "
let splits " "
let xPos 0
let yPos 0
while [not file-at-end?]
[
set line file-read-line
set splits csv-split(line)
set soldierInfo read-from-string splits
set soldierInfo array:from-list soldierInfo
set xPos array:item soldierInfo 0
set yPos array:item soldierInfo 1
set initDir array:item soldierInfo 2
create-unionArtilleryUnits 1
[
setxy xPos yPos
set color blue
set shape "unionarty"
set size 15
set heading initDir
set allegiance "Union"
]
set soldierInfo []
]
file-close
end
;;initialize confederate regiments. See create-ui comments for documentation
to create-ci
file-open "SanitizedSetupFiles/confedInfantrySan.csv"
let soldierInfo []
let line " "
let splits " "
let xPos 0
let yPos 0
while [not file-at-end?]
[
set line file-read-line
set splits csv-split(line)
set soldierInfo read-from-string splits
set soldierInfo array:from-list soldierInfo
set xPos array:item soldierInfo 0
set yPos array:item soldierInfo 1
create-confederateRegiments 1
[
setxy xPos yPos
set color red
set shape "circle"
set size 5
set allegiance "Confederate"
]
set soldierInfo []
]
file-close
end
;;initialize confederate artillery units. See create-ui comments for documentation
to create-ca
file-open "SanitizedSetupFiles/confedArtillerySan.csv"
let soldierInfo []
let line " "
let splits " "
let xPos 0
let yPos 0
while [not file-at-end?]
[
set line file-read-line
set splits csv-split(line)
set soldierInfo read-from-string splits
set soldierInfo array:from-list soldierInfo
set xPos array:item soldierInfo 0
set yPos array:item soldierInfo 1
set initDir array:item soldierInfo 2
create-confederateRegiments 10
[
setxy xPos yPos
set color red
set shape "confederatearty"
set size 15
set heading initDir
set allegiance "Confederate"
]
set soldierInfo []
]
file-close
end