问题描述
如果有的话,请给点时间.
If any one please give some time.
我有一个区域(例如一个殖民地),其边界墙为黑色斑块,在边界内的某个点上有一栋建筑物的建筑物墙为蓝色斑块.人们(品种)通常都在边界和建筑物内部移动.他们也进入和离开边界.由于某种原因(假设是谣言),并且在某种情况下(如果有15位以上的人听到了谣言),他们开始以标题0、90、180和270中的任意一个开始随机移动.因此,我无法解决的问题是检查随机移动的海龟以改变方向,或者在感觉到边界的情况下转回原处或在前方围住一块斑块.
I have an area(say a colony) with boundary wall as black patches and at some point within the boundary there is one building with building wall as blue patches. People(breed) are normally moving inside boundary and the building as well. Also they are entering and going out of the boundary. Due to some reason (suppose rumor) and after certain condition (if more than 15 person hears the rumor) they starts moving randomly with any of the headings 0, 90, 180 and 270. So, the problem I am unable is, to apply check on the turtles(people) randomly moving to change their heading or turn back if they sense the boundary or wall a patch ahead.
我尝试了以下方法,但无法正常工作,它们是通过这些补丁简单地通过的1)问乌龟是否听闻传言?和听到的次数> 1 [ 如果预先修补1的[pcolor] =蓝色[设置自身的标题[heading]-180]
如果提前修补程序的[pcolor] =黑色[设置自身的标题[heading]-180]]
I tried following ways but not working, they simple passes form these patches1) Asked the turtles if heard-rumor? and times-heard > 1 [ if [pcolor] of patch-ahead 1 = blue [set heading [heading] of self - 180]
if [pcolor] of patch-ahead 1 = black [set heading [heading] of self - 180] ]
2)使用边界墙[设置pcolor黑色]和建筑墙[设置pcolor蓝色]设置补丁,然后设置补丁变量boundary-wall?和建筑墙?在这些补丁上为true.进一步问乌龟 如果听到谣言?和听到的次数> 1 [ 如果边界墙?还是建筑墙? [设置自我的标题[heading]-180]]
2) set patches with boundary-wall [set pcolor black] and building-wall [set pcolor blue] and then set patch variables boundary-wall? And building-wall? true on these patches. Further asked the turtles if heard-rumor? and times-heard > 1 [ if boundary-wall? or building-wall? [ set heading [heading] of self - 180 ] ]
过程顺序为
to go
ask people [ ;breed
fd speed
spread-rumor
people-wander ]
end
因此,在传播谣言功能之后
So after spread-rumor function,
to people-wander
if heard-rumor? and times-heard > 1 and inside-boundary?
[
if people-heard-rumor > 10 [ set heading one-of (list 0 90 180 270) ] ];random 360
;people-heard-rumor is a count how many have received rumor
if heard-rumor? or fear-worst? [
; if [pcolor] of patch-ahead 1 = blue [set heading [heading] of self - 180]]
; if [pcolor] of patch-ahead 1 = black [set heading [heading] of self - 180]]
boundary-wall? or temple-wall? [set i? true set heading [heading] of self - 180 show 5] ]
end
我不知道我在做什么错.但可以肯定的是,我没有使用正确的方法.任何帮助深表感谢.
I don’t know what wrong I am doing. But surely I am not using proper way. Any help is deeply thankful.
推荐答案
您从fd speed
开始,因此您的people
将直接通过该命令的障碍,而无需测试障碍.请注意,即使在此之前先测试1个补丁,如果speed
可以大于1,您仍然可以正确地通过障碍.此外,person
在拐角处可能在它的前面和后面都有障碍物,因此反向行驶也可能是一个问题.
You start out with fd speed
so your people
will go right through the barriers on that command without ever testing for a barrier. Note that even if you were to test 1 patch ahead before doing that, if speed
can be greater than 1, you could still go right through the barriers. Furthermore, in a corner a person
might have a barrier both in front of it and behind it, so reversing course can also be a problem.
顺便说一句,[heading] of self
与heading
相同,而转过来说rt 180
更自然.
Btw, [heading] of self
is the same as heading
, and to turn around it is more natural to say rt 180
.
编辑(以回复评论):
这是逐步检查并进行检查的简单示例:
Here is a simple example of moving step by step, checking along the way:
to fd-with-checks [#speed]
repeat #speed [
ifelse (isbarrier? patch-ahead 1) [
stop
] [
fd 1
]
]
end
to-report isbarrier? [#patch]
report pcolor = blue or pcolor = black
end
这篇关于如果前方有障碍物,则无法使非固定海龟改变方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!