【问题标题】:Bouncing turtles in netlogo在 netlogo 中弹跳海龟
【发布时间】:2015-02-18 02:01:27
【问题描述】:

您好,我试图在我的代码中做一些海龟弹跳,但显然我的程序不起作用:

 to bounce 
  if [pcolor] of patch-at dx 400 = white [
    set heading (- heading)
   ]
    if [pcolor] of patch-at 400 dy = white [
      set heading (180 - heading)
     ]
  if abs pxcor = max-pxcor
    [ set heading (- heading) ]
      if abs pycor = (pycor = 25)
    [ set heading (180 - heading) ]
   end

问题是当海龟移动到最大 ycor 时,海龟刚刚越过另一边并出现在世界的底部,所以我认为问题可能是我的设置配置错误世界,但我不知道如何解决它。我忘了提到我用补丁创建了一条水平线,所以海龟会随之反弹。海龟可以用白色的水平柱反弹,问题就在窗口世界的上方。

【问题讨论】:

  • 见弹跳示例,在 NetLogo 模型库的代码示例部分

标签: netlogo agent bounce


【解决方案1】:

代码没问题,把(pycor = 25)换成max-pycor即可:

  if [pcolor] of patch-at dx 400 = white [
    set heading (- heading)
   ]
    if [pcolor] of patch-at 400 dy = white [
      set heading (180 - heading)
     ]
  if abs pxcor = max-pxcor
    [ set heading (- heading) ]
;  if abs pycor = (pycor = 25)
  if abs pycor = max-pycor
    [ set heading (180 - heading) ]

【讨论】:

    猜你喜欢
    • 2020-08-09
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多