全
我试图模拟100个用户(繁殖),每个用户都拥有用户自己的属性,在不同的两次运行中跟踪,比如0& 1。我将这些值作为列表存储在一个列表中并对它们进行排序。它们看起来是这样的[勾0,用户2,attrib 1.9滴答0,用户3,attrib 1.阿特里布9号..。勾0,用户99,attrib 1.阿特里卜9]
当我随机“要求用户”重新分配某些属性时,如何获得匹配值的子集,以匹配由“谁”引用的当前用户?例如,如果上下文中的当前用户是'user 3',如何从列表列表中获得匹配条目的子列表?
提前感谢您的帮助!
发布于 2021-10-15 14:28:41
如果您的列表是结构化的:[ [ TICK# TURTLE# ATT1 ... ATT9 ] ... ]
[
[ 0 0 1 .. 9 ]
[ 0 1 1 .. 9 ]
[ 0 2 1 .. 9 ]
...
[ 0 99 1 .. 9 ]
[ 1 0 1 .. 9 ]
[ 1 1 1 .. 0 ]
... and so on ...海龟的数量总是不变的
然后,您可以计算所需项目的索引。
;; attribute data is in list "data"
LET total-turtles COUNT TURTLES
LET desired-tick 1 ;; number of the tick
LET desired-turtle 7 ;; WHO of turtle
LET desired-attribute 4
;; calculate the sublist index
LET sublist-index desired-tick * total-turtles + desired-turtle
;; get the sublist
LET attribute-sublist ITEM sublist-index data
;; get the value from the sublist
LET attribute-value ITEM (desired-attribute + 2) attribute-sublist 如果将desired-turtle设置为[WHO] OF ONE-OF TURTLES,则使用的是随机海龟。或者你可以用ASK随机的海龟来做上面的事情,它可以使用它自己的WHO。
如果严格按照顺序将信息添加到列表中,则不需要存储tick#或who#,也不需要对其进行排序。
如果让海龟存储它自己的先前属性列表,它可能更容易存储和访问,这取决于您的应用程序。
现在,您已经得到了随机海龟访问历史列表并从其自身历史或其他海龟历史中获取值所需的部分。
https://stackoverflow.com/questions/69581929
复制相似问题