Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-determinism problem with pairs #46

Closed
airstruck opened this issue Jul 20, 2017 · 0 comments
Closed

Non-determinism problem with pairs #46

airstruck opened this issue Jul 20, 2017 · 0 comments

Comments

@airstruck
Copy link

airstruck commented Jul 20, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant