Skip to content

Commit 22262f6

Browse files
committed
Fix calculation of percent-burned by initializing initial-trees before lighting the initial trees on fire in the setup proceedure
1 parent 008348d commit 22262f6

4 files changed

Lines changed: 42 additions & 31 deletions

File tree

IABM Textbook/chapter 3/Fire Extensions/Fire Simple Extension 1.nlogox

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ to setup
88
clear-all
99
;; make some green trees
1010
ask patches [
11-
if (random 100) < density
12-
[ set pcolor green ]
11+
if (random 100) < density [ set pcolor green ]
12+
]
13+
14+
;; Count initial trees before lighting trees on fire to get accurate calculation of percent burned
15+
set initial-trees count patches with [pcolor = green]
16+
17+
ask patches [
1318
;; make a column of burning trees at the left-edge
14-
if pxcor = min-pxcor
15-
[ set pcolor red ]
16-
]
17-
;; keep track of how many trees there are
18-
set initial-trees count patches with [pcolor = green]
19+
if pxcor = min-pxcor [ set pcolor red ]
20+
]
21+
1922
reset-ticks
2023
end
2124

IABM Textbook/chapter 3/Fire Extensions/Fire Simple Extension 2.nlogox

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ to setup
88
clear-all
99
;; make some green trees
1010
ask patches [
11-
if (random 100) < density
12-
[ set pcolor green ]
11+
if (random 100) < density [ set pcolor green ]
12+
]
13+
14+
;; Count initial trees before lighting trees on fire to get accurate calculation of percent burned
15+
set initial-trees count patches with [pcolor = green]
16+
17+
ask patches [
1318
;; make a column of burning trees at the left-edge
14-
if pxcor = min-pxcor
15-
[ set pcolor red ]
16-
]
17-
;; keep track of how many trees there are
18-
set initial-trees count patches with [pcolor = green]
19+
if pxcor = min-pxcor [ set pcolor red ]
20+
]
21+
1922
reset-ticks
2023
end
2124

IABM Textbook/chapter 3/Fire Extensions/Fire Simple Extension 3.nlogox

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@ to setup
88
clear-all
99
;; make some green trees
1010
ask patches [
11-
if (random 100) < density
12-
[ set pcolor green ]
11+
if (random 100) < density [ set pcolor green ]
12+
]
13+
14+
;; Count initial trees before lighting trees on fire to get accurate calculation of percent burned
15+
set initial-trees count patches with [pcolor = green]
16+
17+
ask patches [
1318
;; make a column of burning trees at the left-edge
14-
if pxcor = min-pxcor
15-
[ set pcolor red ]
16-
]
17-
;; keep track of how many trees there are
18-
set initial-trees count patches with [pcolor = green]
19+
if pxcor = min-pxcor [ set pcolor red ]
20+
]
21+
1922
reset-ticks
2023
end
2124
25+
2226
to go
2327
;; stop the model when done
2428
if all? patches [pcolor != red]

IABM Textbook/chapter 3/Fire Extensions/Fire Simple.nlogox

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ to setup
88
clear-all
99
;; make some green trees
1010
ask patches [
11-
if (random 100) < density [
12-
set pcolor green
13-
]
11+
if (random 100) < density [ set pcolor green ]
12+
]
13+
14+
;; Count initial trees before lighting trees on fire to get accurate calculation of percent burned
15+
set initial-trees count patches with [pcolor = green]
16+
17+
ask patches [
1418
;; make a column of burning trees at the left-edge
15-
if pxcor = min-pxcor [
16-
set pcolor red
17-
]
18-
]
19-
;; keep track of how many trees there are
20-
set initial-trees count patches with [pcolor = green]
19+
if pxcor = min-pxcor [ set pcolor red ]
20+
]
21+
2122
reset-ticks
2223
end
2324
@@ -42,7 +43,7 @@ end
4243
<widgets>
4344
<view x="200" wrappingAllowedX="false" y="10" frameRate="30.0" minPycor="-125" height="506" showTickCounter="true" patchSize="2.0" fontSize="10" wrappingAllowedY="false" width="506" tickCounterLabel="ticks" maxPycor="125" updateMode="1" maxPxcor="125" minPxcor="-125"></view>
4445
<monitor x="43" precision="1" y="152" height="60" fontSize="11" width="115" display="percent burned">(count patches with [shade-of? pcolor red]) / initial-trees * 100</monitor>
45-
<slider x="5" step="1.0" y="38" max="99.0" width="185" display="density" height="50" min="0.0" direction="Horizontal" default="57.0" variable="density" units="%"></slider>
46+
<slider x="5" step="1.0" y="38" max="99.0" width="185" display="density" height="50" min="0.0" direction="Horizontal" default="99.0" variable="density" units="%"></slider>
4647
<button x="106" y="96" height="40" disableUntilTicks="true" forever="true" kind="Observer" width="69" display="go">go</button>
4748
<button x="26" y="96" height="40" disableUntilTicks="false" forever="false" kind="Observer" width="70" display="setup">setup</button>
4849
</widgets>

0 commit comments

Comments
 (0)