turtle-set4.0
value1
Reports an agentset containing all of the turtles anywhere in any of the inputs. The inputs may be individual turtles, turtle agentsets, nobody, or lists (or nested lists) containing any of the above.
turtle-set self (turtle-set self turtles-on neighbors) (turtle-set turtle 0 turtle 2 turtle 9) (turtle-set frogs mice)
turtles1.0
turtles
Reports the agentset consisting of all turtles.
show count turtles ;; prints the number of turtles
turtles-at1.0
<breeds>
Reports an agentset containing the turtles on the patch (dx, dy) from the caller. (The result may include the caller itself if the caller is a turtle.)
create-turtles 5 [ setxy 2 3 ] show count [turtles-at 1 1] of patch 1 2 => 5
If the name of a breed is substituted for "turtles", then only turtles of that breed are included.
turtles-here1.0
turtles-here<breeds>-here
Reports an agentset containing all the turtles on the caller's patch (including the caller itself if it's a turtle).
crt 10 ask turtle 0 [ show count turtles-here ] => 10
If the name of a breed is substituted for "turtles", then only turtles of that breed are included.
breed [cats cat] breed [dogs dog] create-cats 5 create-dogs 1 ask dogs [ show count cats-here ] => 5
turtles-on2.0
agentagentset<breeds>agent<breeds>agentset
Reports an agentset containing all the turtles that are on the given patch or patches, or standing on the same patch as the given turtle or turtles.
ask turtles [ if not any? turtles-on patch-ahead 1 [ fd 1 ] ] ask turtles [ if not any? turtles-on neighbors [ die-of-loneliness ] ]
If the name of a breed is substituted for "turtles", then only turtles of that breed are included.
turtles-own
turtles-own [var1<breeds>-own [var1
<breeds>-own, and patches-own keywords, can only be used at the beginning of a program, before any function definitions. It defines the variables belonging to each turtle.
If you specify a breed instead of "turtles", only turtles of that breed have the listed variables. (More than one turtle breed may list the same variable.)
breed [cats cat ] breed [dogs dog] breed [hamsters hamster] turtles-own [eyes legs] ;; applies to all breeds cats-own [fur kittens] hamsters-own [fur cage] dogs-own [hair puppies]
globalspatches-ownbreed<breeds>-own.
下面直接上代码 自己写的
turtles-own [ people-type; ;普通人 ;volunteer; ;志愿者 ; leader; ;意见领袖 safeplace; ;安全区 vision-radius; ;感知范围 escape-speed; ;逃跑速度 ] to init clear-all; set-patch-color; create-people ; create-safeplace; end to set-patch-color ;设置瓦片颜色 ask patches [set pcolor 9] ; end to create-safeplace ;创建安全区 create-turtles count-of-safeplace; [ set color white; set shape "pentagon"; setxy 0 0; set size 8; ] end to create-people ;创建人群 create-turtles count-of-person ;普通人 [ set color green; set shape "person"; ;set vision-radius 100; setxy random-xcor random-ycor; ; set escape-speed 1; ] create-turtles count-of-volunteer ;志愿者 [ set color red; set shape "person"; setxy random-xcor random-ycor; ; set escape-speed 1; ] create-turtles count-of-leader ;意见领袖 [ set color yellow; set shape "person"; setxy random-xcor random-ycor; ;set vision-radius 100; ; set escape-speed 1; ] end to start move-person move-volunteer move-leader end to move-person end to move-volunteer ;ask volunteer ;fd 1 end to move-leader end