【问题标题】:turtles walk to the wall instead of door in netlogo在 netlogo 中,乌龟走到墙而不是门
【发布时间】:2021-04-06 15:26:05
【问题描述】:

我编写了一个代码,将海龟疏散到唯一的出口。但正如我注意到的,海龟分为几组。有海龟向出口门走去,其他的则走到最近的墙边。我想创建一个模拟,所有的海龟都会去出口。这是我的代码。谁能给点建议?

globals [
  ;wall
  door
  goal-x goal-y
  n
]

patches-own [ path? ]

turtles-own [
  direction
  fast?
  other-nearby
]

to setup
  clear-all
  setup-patches
  set-default-shape turtles "person"
  ask n-of number-room1 patches with [pxcor < 47 and pxcor > 0 and pycor < 45 and pycor > 0 and pcolor = black]
  [
    sprout 1 [
      facexy 41 45
      set direction 1
      set color yellow
    ]
  ]
  reset-ticks
end

to setup-patches
  draw-wall
  draw-exit
  
  ask patch 21 41 [
    set plabel-color white
    set plabel "Room1"
  ]
end

to draw-wall
  ask patches with [pxcor <= 38 and pxcor >= 0 and pycor = 45]
    [set pcolor blue]
  ask patches with [pxcor <= 47 and pxcor >= 44 and pycor = 45]
    [set pcolor blue]
  ask patches with [pxcor <= 47 and pxcor >= 0 and pycor = 0]
    [set pcolor blue]
  ask patches with [pxcor = 0 and pycor <= 45 and pycor >= 0]
    [set pcolor blue]
  ask patches with [pxcor = 47 and pycor <= 45 and pycor >= 0]
    [set pcolor blue]
end

to draw-exit
  ask patches with [pxcor <= 43 and pxcor >= 39 and pycor = 45]
    [set pcolor green]
end

to go
  if ticks >= 100 [stop]
  ask turtles [walk]
  tick
end

to walk
  let room1 patches with [pxcor < 47 and pxcor > 0 and pycor < 45 and pycor > 0]
  ;let exitpoint patches with [pxcor < 46 and pxcor > 33 and pycor < 45 and pycor > 32]
  
  ask turtles-on room1
  [face one-of patches with [pxcor <= 43 and pxcor >= 39 and pycor = 47]
    fd 0.01
  ]
  ;ask turtles-on exitpoint
  ;[face one-of patches with [pxcor <= 42 and pxcor >= 38 and pycor = 47]
  ;  fd 0.01
  ;]
end

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    您可以尝试以下 2 个步骤来使其工作:

    1. 检查您的模拟设置(除了右上角的模拟速度滑块),确保uncheck world wrap horizontally & world wrap vertically。如果仍然勾选,则表示海龟可以越过你的垂直/水平边界,出现在另一边。这就是为什么一些海龟正在向墙壁移动的原因,它们假设它们可以通过边界并到达出口,而由于您的代码限制它们会被卡在那里。

    2. 确定设置没问题后,如果你还有一些卡在靠近出口的墙上,你可以尝试用这个替换你的to walk代码:

      to walk
         set heading towards one-of patches with [pcolor = green]
         fd 1
      end
      

    希望这能帮助您解决问题

    【讨论】:

      猜你喜欢
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多