定义全局变量 sample-car
定义属于海龟的变量 speed speed-lim speed-min
对于setup
将全局变量清0
要求patchs执行setup-road
setup-cars
观察 sample-car
将时钟计数器重设为0
结束
对于setup-road
在y坐标位于(-2,2)内的瓦片,设置颜色为白色
结束
对于setup-cars
如果汽车数量大于世界宽度
则执行“ 弹出用户信息,文字:There are too many cars for the amount of road. Please decrease the NUMBER-OF-CARS slider to below "(world-width
+ 1) " and press the SETUP button again. The setup has stopped
结束”
设置海龟的默认初始图形为 车
设置海龟数量“设置颜色 蓝色
设置海龟随机位置
设置海龟面向东
设置速度 speed 为0.1+0~0.9之间的随机浮点数
设置速度上限speed lim 1,下限speed min 0
seperate-cars”
设置sample car为海龟集合的随机一个
请求sample car设置颜色为红色
结束
对于seperate-cars
如果这里有了其他海龟车,那么“前进一步,separate-cars”
结束
对于go
请求海龟“让 car-ahead 是随机海龟前方一格瓦片上的海龟
如果 car-ahead 得到的不是nobody,那么减速(slow-down-car car-ahead),否则加速(speed-up-car)
如果速度小于最小速度,那么让最小速度取代速度
如果速度大于最大速度,那么让最大速度取代速度
让海龟前进速度的步数”
时钟计数器前进1
结束
对于slow-down-car car-ahead
设置速度减少,对主体,返回car-ahead的速度值
对于speed-up-car
设置速度增加