Timer 时间到了,在继续之前先让它工作起来。 globals [ count-tick ] turtles-own [ speed flag-A ] to setup clear-all resize-world 0 50 min-pycor max-p
时间到了,在继续之前先让它工作起来。Timer 时间到了,在继续之前先让它工作起来。 globals [ count-tick ] turtles-own [ speed flag-A ] to setup clear-all resize-world 0 50 min-pycor max-p,timer,counter,netlogo,flags,Timer,Counter,Netlogo,Flags,时间到了,在继续之前先让它工作起来。 globals [ count-tick ] turtles-own [ speed flag-A ] to setup clear-all resize-world 0 50 min-pycor max-pycor ask patches [ setup-road ] reset-ticks end to setup-road if ( pycor < 1 ) and ( pycor > -1 ) [ set pcolo
globals [ count-tick ]
turtles-own [ speed flag-A ]
to setup
clear-all
resize-world 0 50 min-pycor max-pycor
ask patches [ setup-road ]
reset-ticks
end
to setup-road
if ( pycor < 1 ) and ( pycor > -1 ) [ set pcolor white ]
end
to create-car
crt 1 [
set color blue
setxy min-pxcor 0
set heading 90
set speed 1
]
end
to go
if (count turtles-on patch 0 0 = 0) [
create-car
ask (turtles-on patch 0 0) [
set flag-A FALSE
]
]
ask (turtles-on patch 10 0) [
set flag-A TRUE
set count-tick 10
]
if count-tick > 0 [
set count-tick count-tick - 1
ask (turtles-on patch 10 0) with [flag-A = TRUE]
[
set color red
set speed 0
]
]
if count-tick = 0 [
ask (turtles-on patch 10 0) with [flag-A = TRUE]
[
set speed 1
set flag-A FALSE
]
]
if (count turtles-on patch max-pxcor 0 > 0) [
ask min-one-of turtles [who][
die
]
]
set-speed
tick
end
to set-speed
ask turtles with [ xcor < 10 ] [
let turtle-ahead one-of turtles-on patch-ahead 1
ifelse turtle-ahead = nobody
[ set speed 1
fd speed
]
[ set speed 0
]
]
ask turtles with [ 10 < max-pxcor ] [
let turtle-ahead one-of turtles-on patch-ahead 1
ifelse turtle-ahead = nobody
[ set speed 1
fd speed
]
[ set speed 0
]
]
end
globals [ count-tick ]
turtles-own [ speed flag-A ]
to setup
clear-all
resize-world 0 50 min-pycor max-pycor
ask patches [ setup-road ]
reset-ticks
end
to setup-road
if ( pycor < 1 ) and ( pycor > -1 ) [ set pcolor white ]
end
to create-car
crt 1 [
set color blue
setxy min-pxcor 0
set heading 90
set speed 1
set flag-A FALSE
]
end
to go
if (count turtles-on patch 0 0 = 0) [
create-car
]
ask (turtles-on patch 10 0) [
set flag-A TRUE
set count-tick 10
]
ask (turtles-on patch 10 0) with [flag-A = TRUE] [
set color red
set speed 0
set count-tick count-tick - 1
if count-tick = 0 [
set speed 1
set flag-A FALSE
]
]
if (count turtles-on patch max-pxcor 0 > 0) [
ask min-one-of turtles-on patch max-pxcor 0 [who][
die
]
]
ask turtles [ forward speed ]
tick
end