paulofmandown / rotLove

Roguelike Toolkit in Love. A Love2D/lua port of rot.js
http://paulofmandown.github.io/rotLove/
Other
258 stars 25 forks source link

Non-determinism problem with pairs #46

Closed airstruck closed 7 years ago

airstruck commented 7 years ago

Use of pairs causes some map generators to be non-deterministic. Iteration order of pairs is undefined, so code like this won't give the same result every time it's run:

for k,_ in pairs(self._walls) do
    if self._walls[k]>1 then table.insert(prio2, k)
    else table.insert(prio1, k) end
end

This more or less defeats the point of having a seedable RNG. Most likely also a problem in rot.js since iteration order of JS for..in construct is similarly undefined (per spec, but maybe some implementations are more predictable).

Fixing this would likely also fix #36, since pairs is mostly used to iterate over tables with x..','..y keys.