首页 > 解决方案 > 如何“追踪”乌龟?

问题描述

我想跟踪如下创建的海​​龟:

要跟踪的海龟是对象。我想过访问路径/链接或更改创建的海龟的颜色(例如,询问 this-object [ set color red ]),但我隐藏了海龟,所以它没有意义。您对我如何在网络中跟踪这只乌龟的路径有任何想法吗?(你可以想象一辆发生事故的汽车,但司机并没有停下来,继续行驶,它又发生了新的事故……我想追踪的不仅是事故,还有造成事故的汽车,如果可能的话。

我希望你能帮助我。谢谢

标签: netlogo

解决方案


You have now asked essentially the same question at least 10 times in slightly different ways. It's clear that none of the answers have answered your question, but it's also clear that you aren't understanding any of the answers. While I would normally ask you to post what you have tried so far, it's probably best to start from the beginning.

Here is a complete model that does what you want. I have put print statements at key points so that you can see that it does what you want.

breed [people person]
people-own
[ my-objects
]

breed [objects object]
objects-own
[ my-people
]

to setup
  clear-all
  create-people 5
  [ setxy random-xcor random-ycor
    set color red
    set my-objects []
  ]
  ask one-of people
  [ hatch-objects 1
    [ set color blue
      set my-people (list myself)
      let child self
      ask myself [ set my-objects (list child) ]
    ]
  ]
  reset-ticks
end

to go
  ask one-of objects [move-object]
  tick
end

to move-object
  let target one-of people
  while [target = first my-people] [set target one-of people]
  let this-object self
  ask target
  [ type self type " Objects old: " print my-objects
    set my-objects fput this-object my-objects
    type self type " Objects new: " print my-objects
  ]
  type self type " Owners old: " print my-people
  set my-people fput target my-people
  move-to target
  type self type " Owners new: " print my-people
end

If you want to make any progress on your code, you need to completely understand this model first. Don't just copy the relevant bits into your code and try to amend. Instead, make a new NetLogo model for this code and understand every line - what it does, how it works. Once you understand it, you can then use the concepts and approach in your own model.


推荐阅读