NetLogo / Tortoise

Compiler and runtime engine for NetLogo models that runs in JavaScript 🐢
https://netlogoweb.org
Other
56 stars 27 forks source link

The `in-radius` prim gives agents in a different order than desktop #212

Closed LaCuneta closed 4 years ago

LaCuneta commented 4 years ago

This code will give different results in desktop/headless than in NetLogo Web:

to in-radius-order-check
  clear-all
  resize-world -4 4 -4 4
  random-seed 123456

  crt 30 [ setxy random-xcor random-ycor ]

  ask one-of turtles [
    show [who] of turtles in-radius 3
  ]
end

Or, in a form suitable for the Tortoise.txt language tests (results from NetLogo 6.1.1):

InRadiusGivesSameOrder
  globals [ check-list ]
  O> resize-world -4 4 -4 4
  O> random-seed 123456
  O> crt 30 [ set color one-of [red yellow white] setxy random-xcor random-ycor ]
  O> set check-list []
  O> ask one-of turtles [ ask other turtles in-radius 3 [ set check-list lput who check-list ] ]
  check-list => [23 21 18 7 11 2]

The likely issue is desktop optimizations for the in-radius prim causing the backing collection order to be different before using of or ask to access the shuffler to get the agents out. But it's strange that this has not caused an issue before in the docking tests for models that use in-radius extensively, like Fireflies or Flocking.