以下代码创建 2 辆汽车,然后在它们后面添加手推车(称为“跟随者”)。该代码旨在将追随者均匀地分布在汽车后面,一个接一个,然后将它们连接在一起。然后,当汽车移动时,他们应该拉动追随者。但只有第一个关系(汽车和最近的追随者)似乎在工作。
globals [small len_small ]
breed [cars car]
breed [followers follower]
cars-own [reg no_foll len]
followers-own [reg]
to setup
clear-all
set small 2
set len_small 7
ask patches with [pycor >= 5 or pycor <= 1][set pcolor red]
ask patches with [pycor = 4 ][set pcolor blue]
ask patches with [ pycor = 2][set pcolor blue + 1]
ask patches with [pycor = 3][set pcolor white]
make_small
reset-ticks
end
to go
ask cars [forward 2]
end
to make_small
create-cars small [move-to one-of patches with [pcolor = white ]
set shape "circle" set color red set reg who set no_foll 0 set len len_small
set heading one-of [90 270]]
create-followers (len_small - 1) * small [ set shape "car" set color red move-to one-of cars with [color = red and no_foll < (len_small - 1)]
set heading [heading] of one-of cars-here + 180 set reg [reg] of one-of cars-here ask one-of cars-here [set no_foll no_foll + 1]]
form_small_car
end
to form_small_car
ask followers with [color = red ] [while [any? other turtles-here with [reg = [reg] of myself]][forward 1]]
ask cars with [color = red] [let foll_behind_list followers-on patch-ahead -1 let foll_behind one-of foll_behind_list with [reg = [reg] of myself] create-link-to foll_behind [tie]]
ask followers with [color = red and any? followers-on patch-ahead -1] [let foll_behind_list followers-on patch-ahead -1 let foll_behind one-of foll_behind_list with [reg = [reg] of myself ]
create-link-to foll_behind [tie]]
end
我哪里错了? [顺便说一句,在这个示例代码中,追随者的选择是过度的,但在更大的模型中需要到位,以便只有追随者连接到同一辆车链接]
谢谢,
凯文