2014-07-05 36 views
0
to setup 
    ca 
    reset-ticks 
    ask patches [ 
    set inside? (abs pycor < 10 and abs pxcor < 10)  
    set exit? false 
    ask patch 11 0 [ set pcolor lime set exit? true] 
    ] 

    repeat initial-population [ ; start condition turtles with any other turtles on neighbors 
    ask one-of patches with [ 
     inside? and (not any? other turtles-here) and (not any? turtles-on neighbors)] [ 
     sprout 1 [ 
     set color blue 
     set size 1 
     ]]] 
end 

to go 
    tick 
    define-neighbors-radius-2 
    move 
end 

to define-neighbors-radius-2 
    ask turtles [  
    set neighbors-ahead2 patches at-points [[2 1] [2 0] [2 -1]] 
    set neighbors-for-y-up2 patches at-points [[2 0] [2 -1] [1 -2] [0 -2] [-1 -2]] with [inside?] 
    set neighbors-for-y-down2 patches at-points [[-1 2] [0 2] [1 2] [2 1] [2 0]] with [inside?] 
    ] 
end 

to move 
;; my intent to move turtles to exit without their neighbors are occupied by other turtles,   ;;that is the 8 patches around turtles are empty until exit? 

ask turtles[ 
    ifelse inside? [ 
     if ycor = 0 [ ;strategy to turtles with in front exit 
     ifelse exit? [ 
      set heading 90 
      fd .5 
     ] 
     [ 
      facexy 11 0 
      if (not any? turtles-on neighbors) and (not any? turtles-on neighbors-ahead2) [ 
      fd .5 
      ] 
     ] 
     ] 
     if ycor > 0 [  ; strategy to turtles occupied "bottom-side" of inside? 
     facexy 11 0 
     if (not any? turtles-on neighbors) and (not any? turtles-on neighbors-for-y-up2) [ 
      fd .5 
     ] 
     ] 
     if ycor < 0 [  ; strategy to turtles occupied "down-side" of inside? 
     facexy 11 0 
     if (not any? turtles-on neighbors) and (not any? turtles-on neighbors-for-y-down2) [ 
      fd .5 
     ] 
     ] 
    ] 
    [ 
     set heading 90 
     fd .5 
    ] 
    ] 
end 

我尝试移动海龟退出但不是所有的海龟移动,为什么? 另外,龟必须与ycor = 0出去,这是斜方向不允许,因为邻居会占用补丁不在里面! 不能公开这个问题,因为“看起来像我的帖子主要是代码”,所以说说我的生活: 认真我的意图是在出口前创建一个人群并设置一些规则来延迟乌龟流出口,因为这我需要邻居为空来显示代理之间的交互。 (也接受一些建议设置这种互动),但目前乌龟到达出口! 谢谢移动海龟并创建一个目标人群

+1

“也,龟必须与ycor = 0出去,那就是斜方向不允许,因为邻居会占用补丁不在里面“ - 不能对这句话有任何意义 –

+0

抱歉,英文不是我的品质。 – user3780602

+0

海龟从补丁10 0退出,在同样的pycor出口修补,所以ycor = 0,而不是从补丁10 1或10 -1开始,就像代码示例中那样。 – user3780602

回答

0

此代码的一个问题是,你有三个if s看起来你只希望其中一个每次运行,但它们可能会触发多于一个。您有:

if ycor = 0 [ ...commands #1... ] 
if ycor > 0 [ ...commands #2... ] 
if ycor < 0 [ ...commands #3... ] 

但龟的可能被命令1号或2改变。所以#1和#2都可能运行,或者#2和#3都可能运行,或许还有其他组合。我假设你打算每个龟只应每个时钟周期的移动一次,所以我建议你重写此为:

ifelse ycor = 0 
    [ ...commands #1... ] 
    [ ifelse ycor > 0 
     [ ...commands #2... ] 
     [ ...commands #3... ] ] 

别的东西,应该被固定在这个代码:

  • reset-ticks应该在setup结束,不在开始附近。它告诉NetLogo安装完成。
  • tick应该在go的末尾去,而不是在开始附近。它告诉NetLogo一个勾号已经完成。

我不知道我指出的这些问题中的任何一个实际上是否会导致您看到的意外行为。也许这个bug只是通过阅读代码而不是显而易见的。在这种情况下,您有两种可能的行动方案:

1)备份。扔掉这个破碎的代码,并返回到您的模型的最后一个版本,其中只包含您已验证可正常工作的代码。然后再试一次,但这次不要一次添加太多的新代码。尝试对代码进行非常小的改进,然后开始工作,然后再进行下一个小改进。等等。如果在任何时候遇到困难,请到这里,展示您的代码,并询问具体的问题。这个问题应该比你当前的问题更容易回答。 “这里有大量的代码不起作用,很有帮助!”很难回答。

2)通过自己调查你的问题来继续。你写道:“并非所有的海龟都移动,为什么?“也许有人可以通过阅读你的代码来回答这个问题;我不能(除非我上面的第一个猜测是正确的)为了弄清楚,我必须自己运行代码并对它进行实验。做一些事情,比如尝试用一只乌龟来运行它,看看这种情况是否失败;在代码中添加print语句,显示每个乌龟的坐标和运动,这样我就可以尝试找出哪只乌龟出了问题,在什么条件下;等等,这就像侦探工作,或者像在实验室里做化学实验一样

+0

我可以在netlogo中使用arcsin函数吗?我怎么写它? – user3780602

+0

请打开一个新问题来提问。 –

+0

我不能做这样的问题。堆栈溢出规则'..我不知道 – user3780602