我正在netlogo上制作一个迷宫,我想这样做,一旦它试图走进紫色线条,它就会留在自己的补丁而不是前进。这将是什么命令?我尝试使用bk 1来反转fd 1但它不能一直工作
答案 0 :(得分:2)
你可以像这样撤消你的步骤:
ask turtles [
fd 1
if pcolor = violet [fd -1]
]
或者你可以提前检查Marzy回答。基本上,这是要求宽恕与许可的区别: - )
答案 1 :(得分:1)
我希望这个例子能回答你的问题:
turtles-own [target]
to setup
clear-all
reset-ticks
ask n-of 100 patches [
set pcolor red
]
create-turtles 1
[ move-to one-of patches with [pcolor != red]
set heading 90
set target one-of patches with [pcolor != red]
ask target
[
set pcolor green
]
]
end
to go
ask turtles
[ifelse pcolor != green
[
ifelse [pcolor] of patch-ahead 1 != red
[
Your-Move-Function
]
[
Your-Bounce-Function
]
leave-a-trail
]
[stop
print ticks
]
]
tick
end
to Your-Move-Function
let t target
face min-one-of all-possible-moves [distance t]
fd 1
end
to Your-Bounce-Function
let t target
face min-one-of all-possible-moves [distance t]
end
to-report all-possible-moves
report patches in-radius 1 with [pcolor != red and distance myself <= 1 and distance myself > 0 and plabel = "" ]
end
to leave-a-trail
ask patch-here [set plabel ticks]
end
这是它的工作原理:
随机贴片的颜色为红色以显示墙壁或障碍物,一只乌龟在随机位置创建,随机目标为绿色:
我使用了一个变量来存储龟可以踩的所有可用补丁,但是由于我已经考虑了乌龟的目标,乌龟选择了最接近目标的一个补丁,因为我在某些情况下注意到了它可能会进入圆圈我已经要求乌龟留下刻度号码,这是它作为一个空格的移动号码,您可以使用一个变量来指定该路径是否已被选中。