首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我动不动乌龟

我动不动乌龟
EN

Stack Overflow用户
提问于 2022-11-01 23:02:07
回答 1查看 28关注 0票数 0

我刚刚开始在网络徽标中创建一个基于代理的模型。我有两个形状文件,我想让我的海龟在我的网络地图上移动。目前,我只能在我的模型中加载shapefiles。有人能告诉我如何在我的网络地图上移动乌龟吗?

到目前为止,我的代码如下:

代码语言:javascript
复制
extensions [gis]
breed [cars car]
turtles-own [destination]
globals [
  states-dataset 
  car-blue]

to custom-clear
  reset-ticks
  clear-turtles
  clear-patches
  clear-drawing
  clear-all-plots
end

to setup
  clear-all
  custom-clear
  ask patches [set pcolor green - 3]
  set states-dataset gis:load-dataset "C:/Users/ADMIN/Documents/QGIS/Export Netlogo/Format .shp/state.shp"

  gis:set-world-envelope gis:envelope-of states-dataset
  gis:set-drawing-color yellow
  gis:draw states-dataset 1

  set route-car-blue gis:load-dataset     "C:/Users/ADMIN/Desktop/routefiles/Shapefile/car/route-car-blue.shp"
  gis:set-drawing-color blue
  gis:draw angkot-permatabiru 1.5

  foreach gis:feature-list-of route-car-blue
  [car-pb -> let location gis:location-of gis:centroid-of car-pb
   create-turtles 5 [
    set xcor item 0 location
    set ycor item 1 location
    set shape "car"
    set size 1
  ]]
end

to go
  ask turtles [
  let new-location one-of [link-neighbors] of destination
  move-to new-location
  set destination new-location]
  tick
end

有人知道怎么修改我的密码吗?我想让我的海龟移动基于我的网络地图。

EN

回答 1

Stack Overflow用户

发布于 2022-11-02 08:41:58

问题可能在于destinationnew-location的循环性。您将new-location定义为destinationlink-neighbor,但是由于还没有destination,所以这个new-location设置为nobody。然后,将您的destination设置为您的new-location,这也将destination设置为无人,最终形成一个没有任何运动发生的圆圈。

解决这个问题的方法是在destination期间为每个海龟定义一个setup

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74282679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档