Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is more of a stab in the dark than anything, but I think that using a for loop to set the states of the "cells" is causing this bug.
- Let's say this is your grid:
- ▓▓ - A living cell
- ░░ - A non-living cell
- ░░░░░░░░░░
- ░░▓▓▓▓▓▓░░
- ░░▓▓░░▓▓░░
- ░░▓▓▓▓▓▓░░
- ░░░░░░░░░░
- Here we have the 3x3 "donut" shape that causes the bug.
- Your script runs through this top left to bottom right.
- It does nothing until it reaches the top-middle non-living cell. It recognises that this has three neighbours, and sets it to living.
- ░░░░▓▓░░░░
- ░░▓▓▓▓▓▓░░
- ░░▓▓░░▓▓░░
- ░░▓▓▓▓▓▓░░
- ░░░░░░░░░░
- This means that the next cell scanned now has three neighbours, and thus:
- ░░░░▓▓▓▓░░
- ░░▓▓▓▓▓▓░░
- ░░▓▓░░▓▓░░
- ░░▓▓▓▓▓▓░░
- ░░░░░░░░░░
- The next two cells have nothing happen to them as they both have exactly two neighbours. However, the cell at (3, 4) is now overpopulated:
- ░░░░▓▓▓▓░░
- ░░▓▓░░▓▓░░
- ░░▓▓░░▓▓░░
- ░░▓▓▓▓▓▓░░
- ░░░░░░░░░░
- And the one at (5, 4) is now ready to populate:
- ░░░░▓▓▓▓░░
- ░░▓▓░░▓▓▓▓
- ░░▓▓░░▓▓░░
- ░░▓▓▓▓▓▓░░
- ░░░░░░░░░░
- This goes on as you'd expect it to.
- Basically, by changing the state of the cell as you test its conditions, you affect the conditions of the surrounding cells. What you want to be doing is reading the conditions of all the cells and setting a seperate variable for their desired state.
- Then, at the end of the update() function, you run a second for loop which sets the actual value to the desired value. This means that the cells are all read and dealt with before they change, and stops the distorting of cell states.
- Hope this made sense and helps to fix the issue!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement