netlogo - 在 netlogo 中,乌龟走到墙而不是门
问题描述
我编写了一个将海龟疏散到唯一出口的代码。但正如我注意到的那样,海龟分为几组。有海龟向出口门走去,其他的则走到最近的墙边。我想创建一个模拟,所有的海龟都会去出口。这是我的代码。有人可以建议吗?
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
解决方案
您可以尝试以下 2 个步骤来使其工作:
检查你的模拟设置(除了右上角的模拟速度滑块),确保取消选中 world wrap Horizontal 和 world wrap vertical。如果仍然勾选,则表示海龟可以越过你的垂直/水平边界,出现在另一边。这就是为什么一些海龟正在向墙壁移动的原因,他们假设他们可以通过边界并到达出口,而由于您的代码限制,他们会被卡在那里。
确定设置没问题后,如果你还有一些卡在靠近出口的墙上,你可以尝试用下面的代码替换你的
to walk
代码:to walk set heading towards one-of patches with [pcolor = green] fd 1 end
希望这将帮助您解决问题
推荐阅读
- python - TypeError:当我尝试识别照片时,“元组”对象无法解释为整数
- css - Cystoscape - 节点和辐条模型 - 需要弹性和运动
- java - 为什么 SSL 在构建 jar 中不起作用?
- javascript - Switch 语句以检查某些内容是否在预定义的数组中
- elasticsearch - Fluentd - 无法与 Elasticsearch 通信,重置连接并重试。getaddrinfo:名称或服务未知(SocketError)
- node.js - 为什么秘密管理工具 SecretHub 可以在本地工作,但不能在 heroku 生产中工作?
- mysql - 暂时锁定 SQLite/MySQL 数据库
- python - TypeError:无法将数组数据从 dtype('float64') 转换为 dtype('
我正在尝试运行此代码以进行分析。
import numpy as np import pandas as pd import xarray as xr import matplotlib.pyplot as plt GPCC
- javascript - HTML 按钮重定向
- django - 当我使用 django-ckeditor 没有错误时,如何在 Django 模板上应用多个过滤器?