因此,当我使用我创建的报告程序进行计算时,我正在尝试按其值对列表进行排序。这是代码:
globals [ goal Smin Smax distWeight colorWeight ]
turtles-own [ S Ac ]
to setup
ca
set Smin 2
set Smax 6
set distWeight 2
set colorWeight 3
ask n-of n patches [
sprout 1 [
set color one-of [ red blue ]
set heading one-of [ 90 270 ]
set S []
]
]
reset-ticks
end
to go
ask turtles [
foreach sort other turtles [
ask ? [
if Smin < Sim myself ? [
if Sim myself ? < Smax [
set S lput ? S
]
]
]
]
;how do I do this? this does not work
set Ac max-one-of S [Sim myself ?]
]
tick
end
to-report Sim [Ame Ao]
report (Sfcolor Ame Ao * colorWeight) + (Sfdistance Ame Ao * distWeight)
end
to-report Sfcolor [Ame Ao]
ifelse [color] of Ame = [color] of Ao
[ report 1 ]
[ report 0 ]
end
to-report Sfdistance [Ame Ao]
report 1 / euclidean-distance [xcor] of Ame [ycor] of Ame [xcor] of Ao [ycor] of Ao
end
to-report euclidean-distance [x y x1 y1]
report sqrt ((x1 - x) ^ 2 + (y1 - y) ^ 2)
end
to-report Gain [ SimVal ]
report ( Smax - Smin ) / Smax - SimVal
end
现在我想要一个名为Ac
的变量来包含乌龟,它是S的元素,具有最高的Sim值。我试图通过
set Ac max-one-of S [Sim myself ?]
但它不起作用。
答案 0 :(得分:1)
如果你确切地说它为什么不起作用会有所帮助。
但对于初学者来说,这句话是在foreach循环之外,所以呢?没意思。