使海龟根据列表中的排名顺序移动一次 [英] Make turtles move ONCE according to their ranked order in a list
问题描述
这个问题是基于我先前的问题2提出的.我一直在努力为自己的海龟按排名排序,并按自有因素进行排名.然后要求他们按排名顺序移动.该部分工作得很好,可以在以下位置找到代码:将乌龟分配给排名netlogo中的数字
This question is built off my previous 2. I've been working to get a rank-ordered list for my turtles, ranked by an owned factor. They're then required to move in ranked order. That part works perfectly fine, and the code can be found at: Assigning turtles a ranked number in netlogo
问题:使用该代码,它们以正确的顺序移动,而不是一次移动,该程序似乎在为列表中的每只乌龟连续不断地重新运行它,因此10只世界中的第一只乌龟结束了向上移动10次,第二次移动9次,等等.
The problem: using that code, they're moving in the correct order but instead of moving once, the program seems to be continuously re-running it for every turtle in the list so the first turtle in a world of 10 ends up moving 10 times, the second moves 9 times, etc.
我对此完全感到困惑,但是我需要停止它.他们应该移动一次,然后为该滴答作答.想法?
I'm completely stumped on this, but I need it to stop. They're supposed to move once and be done for that tick. Ideas?
列表创建代码为:
let rank-list sort-on [sociability] turtles
let ranks n-values length rank-list [ ? ]
(foreach rank-list ranks [ask ?1 [set social_rank ?2] ] )
;;you can replicate the problem with this movement proc, or the full code in the link above
ask turtles [foreach rank-list [ask ? [set heading 270 forward 1]]]
推荐答案
在此行:
ask turtles [foreach rank-list [ask ? [set heading 270 forward 1]]]
您要让每只乌龟对rank-list
中的每只乌龟执行命令.
You're asking each turtle to execute a command for each turtle in your rank-list
.
只需删除ask turtles
部分.
作为更一般的注释:foreach
是列出ask
对代理集的含义.它们都执行相同的基本操作,即对集合"的每个项目执行命令.代理集是唯一代理的无序集合.列表是可能重复的任何类型的项目的有序集合.
As a more general note: foreach
is to lists what ask
is to agentsets. They both do the same basic thing, which is to perform a command for each item of a "collection". Agentsets are unordered collections of unique agents. Lists are ordered collections of possibly duplicated items of any type.
这篇关于使海龟根据列表中的排名顺序移动一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!