0

因此,当使用我创建的报告程序计算时,我试图按列表的值对列表进行排序。这是代码:

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 ?]

但它不起作用。

4

1 回答 1

1

如果您确切地说出它为什么不起作用,那将会有所帮助。

但是对于初学者来说,该语句在 foreach 循环之外,所以?不会有任何意义。

于 2013-06-19T18:56:36.467 回答