globals [
wall
window
door
goal-x goal-y
n
]
patches-own [patch?
walls
windows
doors]
turtles-own [direction
fast?
fear?
other-nearby]
to setup
ca
setup-patches
set-default-shape turtles "person" ;like people
ask n-of number-room1 patches with [pxcor < 71 and pycor < 79 and pxcor >
0 and pycor > 50 and pcolor = black] ; makes turtles sprout on black patches = room1
[sprout 1 [
if [count turtles-here] of neighbors4 = 3 [congest]
set size 10 ;; setting turtle size
facexy 124 79 ; initial direction faceing
set direction 1
set color yellow ;initial color
if xcor mod 2 != 0 [set fast? false]
if xcor mod 2 = 0 [set fast? true]
if turtles != red [set fear? false]
]
]
ask n-of number-room2 patches with [pxcor < 112 and pycor < 79 and pxcor > 71 and pycor > 50 and pcolor = black] ; makes turtles sprout on black patches= room2
[sprout 1 [
if [count turtles-here] of neighbors = 3 [congest]
set size 10 ;; setting turtle size
facexy 124 79 ; initial direction faceing
set direction 1
set color yellow ;initial color
if xcor mod 2 != 0 [set fast? false]
if xcor mod 2 = 0 [set fast? true]
if turtles != red [set fear? false]
]
]
ask n-of number-room3 patches with [pxcor < 82 and pycor < 36 and pxcor > 0 and pycor > 0 and pcolor = black] ; makes turtles sprout on black patches= room3
[sprout 1 [
if [count turtles-here] of neighbors = 3 [congest]
set size 10 ;; setting turtle size
facexy 124 79 ; initial direction faceing
set direction 1
set color yellow ;initial color
if xcor mod 2 != 0 [set fast? false]
if xcor mod 2 = 0 [set fast? true]
if turtles != red [set fear? false]
]
]
ask n-of number-room4 patches with [pcolor = brown] ; makes turtles sprout on black patches= room4
[sprout 1 [
if [count turtles-here] of neighbors = 3 [congest]
set size 10 ;; setting turtle size
facexy 124 79 ; initial direction faceing
set direction 1
set color yellow ;initial color
if xcor mod 2 != 0 [set fast? false]
if xcor mod 2 = 0 [set fast? true]
if turtles != red [set fear? false]
if pxcor <= 120 and pxcor >= 90 and pycor = 12 [walk1]
if pxcor <= 120 and pxcor >= 90 and pycor = 24 [walk1]
if pxcor < 90 and pxcor >= 85 and pycor >= 12 and pycor < 24 [set heading 0]
]
]
fear ;calls function fear
reset-ticks
end
to walk1 ;function earlier called
ifelse ((random 2) = 0); to allow turtles randomly decide if they will go
left or right in rows.
[
go-left
]
[
go-right
]
end
to go-left
set heading 90
end
to go-right
set heading 270
end
to congest
stop
end
to setup-patches
draw-wall;wall, Windows and Doors
draw-exit ; Doors
draw-row ; sitting area
draw-corridor-cafeteria
;Labels
ask patch 41 60[
set plabel-color white
set plabel "Room1 = Office"
]
ask patch 95 60[
set plabel-color white
set plabel "Room2 = Management"
]
ask patch 77 44[
set plabel-color white
set plabel "Corridor"
]
ask patch 41 18[
set plabel-color white
set plabel "Room3 = Meeting Room"
]
ask patch 112 18[
set plabel-color white
set plabel "Room4 = Cafeteria"
]
end
to draw-wall
ask patches with [pxcor <= 120 and pxcor >= 0 and pycor = 79]
[set pcolor blue]
ask patches with [pxcor <= 132 and pxcor >= 129 and pycor = 79]
[set pcolor blue]
ask patches with [pycor <= 79 and pycor >= 0 and pxcor = 132]
[set pcolor blue]
ask patches with [pycor <= 79 and pycor >= 0 and pxcor = 0]
[set pcolor blue]
ask patches with [pxcor <= 34 and pxcor >= 0 and pycor = 0]
[set pcolor blue]
ask patches with [pxcor <= 132 and pxcor >= 43 and pycor = 0]
[set pcolor blue]
ask patches with [pxcor <= 112 and pxcor >= 109 and pycor = 50]
[set pcolor blue]
ask patches with [pxcor <= 50 and pxcor >= 0 and pycor = 50]
[set pcolor blue]
ask patches with [pxcor <= 84 and pxcor >= 79 and pycor = 36]
[set pcolor blue]
ask patches with [pxcor <= 70 and pxcor >= 0 and pycor = 36]
[set pcolor blue]
ask patches with [pxcor <= 132 and pxcor >= 93 and pycor = 36]
[set pcolor blue]
ask patches with [pycor <= 79 and pycor >= 50 and pxcor = 71]
[set pcolor blue]
ask patches with [pycor <= 79 and pycor >= 50 and pxcor = 112]
[set pcolor blue]
ask patches with [pycor <= 36 and pycor >= 0 and pxcor = 82]
[set pcolor blue]
ask patches with [pxcor <= 100 and pxcor >= 59 and pycor = 50]
[set pcolor blue]
end
to draw-exit
;room1
ask patches with [pxcor < 59 and pxcor > 50 and pycor = 50]
[set pcolor green]
;room2
ask patches with [pxcor < 109 and pxcor > 100 and pycor = 50]
[set pcolor green]
;room3
ask patches with [pxcor < 79 and pxcor > 70 and pycor = 36]
[set pcolor green]
;room4
ask patches with [pxcor < 93 and pxcor > 84 and pycor = 36]
[set pcolor green]
;main exit
ask patches with [pxcor < 130 and pxcor > 120 and pycor = 79]
[set pcolor red]
;second exit
ask patches with [pxcor < 43 and pxcor > 34 and pycor = 0]
[set pcolor red]
ask patches with [pxcor < 132 and pxcor > 112 and pycor = 50]
[set pcolor 1]
end
to draw-row
ask patches with [pxcor <= 123 and pxcor >= 93 and pycor = 12]
[set pcolor brown]
ask patches with [pxcor <= 123 and pxcor >= 93 and pycor = 24]
[set pcolor brown]
end
to draw-corridor-cafeteria
ask patches with [pxcor <= 93 and pycor <= 24 and pxcor > 82 and pycor >= 12] [set pcolor 2]
ask patches with [pxcor < 132 and pycor <= 24 and pxcor >= 123 and pycor >= 12] [set pcolor 2]
end
to go
ask turtles with [pcolor != red] [walk] ;asks turtles with patch color not equal to red carry out function walk
spread-fear
tick
end
to spread-fear ; When an agent with fear is near another agent withiut fear, the other has a chance of also getting scared according to slider on interface, spreadfear
ask turtles with [fear? = true and pcolor != red]
[ ask other turtles-here with [fear? = false]
[if (random-float 100) < spreadfear [getscared]]
]
end
to getscared ;changes turtles
set color red
set fear? true
end
to fear
;ask some initialy scared turtles to get scared
ask n-of initially-scared-1 turtles with [size = 10] [getscared]
ask n-of initially-scared-2 turtles with [size = 10] [getscared]
ask n-of initially-scared-3 turtles with [size = 10] [getscared]
ask n-of initially-scared-4 turtles with [size = 10] [getscared]
end
to walk
let room1 patches with [pxcor <= 70 and pycor <= 78 and pxcor >= 1 and pycor >= 51]
let room2 patches with [pxcor < 112 and pycor < 79 and pxcor > 71 and pycor > 50]
let room3_lft patches with [pxcor < 20 and pycor < 36 and pxcor > 0 and pycor > 0]
let room3_rgt patches with [pxcor < 82 and pycor < 36 and pxcor >= 20 and pycor > 0]
let room4 patches with [pxcor < 132 and pycor < 36 and pxcor > 82 and pycor > 24]
let corridor_1 patches with [pxcor <= 70 and pycor <= 50 and pxcor >= 0 and pycor >= 36]
let corridor_2 patches with [pxcor <= 131 and pycor <= 50 and pxcor >= 71 and pycor >= 36]
ask turtles-on room1
[ face one-of patches with [pxcor < 59 and pxcor > 50 and pycor = 51]
]
let exit-room-1 patches with [pxcor < 59 and pxcor > 50 and pycor > 50 and pycor <= 51]
ask turtles-on exit-room-1
[set heading 180]
ask turtles-on room2
[ face one-of patches with [pxcor < 109 and pxcor > 100 and pycor = 51]
]
let exit-room-2 patches with [pxcor < 109 and pxcor > 100 and pycor > 50 and pycor <= 51]
ask turtles-on exit-room-2
[set heading 180]
ask turtles-on room3_rgt
[ face one-of patches with [pxcor < 79 and pxcor > 70 and pycor = 35]
]
ask turtles-on room3_lft
[ face one-of patches with [pxcor = 70 and pycor > 0 and pycor < 36]
]
let exit-room-3 patches with [pxcor < 79 and pxcor > 70 and pycor >= 35 and pycor < 36]
ask turtles-on exit-room-3
[set heading 0]
ask turtles-on room4
[ face one-of patches with [pxcor < 93 and pxcor > 84 and pycor = 35]
]
let exit-room-4 patches with [pxcor < 93 and pxcor > 84 and pycor >= 35 and pycor < 36]
ask turtles-on exit-room-4
[set heading 0]
ask turtles-on corridor_1
[set heading 90]
ask turtles-on corridor_2
[ face one-of patches with [pxcor <= 131 and pxcor >= 113 and pycor = 50]
]
let mainexit patches with [pxcor <= 131 and pycor < 79 and pxcor >= 113 and pycor >= 50]
ask turtles-on mainexit
[ face one-of patches with [pxcor <= 129 and pxcor >= 121 and pycor = 79]
]
let mainexitdoor patches with [pxcor <= 129 and pxcor >= 121 and pycor = 79]
if fear? = true [fd .5]
if fear? = false [fd .8]
ask turtles-on mainexitdoor [evacuate]
end
to evacuate
set color green
if all? turtles [pcolor = green] [ stop ]
end
当所有特工到达主出口门后,我无法停止滴答,并且无法在监视器框中显示撤离的特工(用[pcolor = green]计数的海龟)以及在图空间中的持续时间(图数) [pcolor = green]的海龟)。
预先感谢