-
Notifications
You must be signed in to change notification settings - Fork 61
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
Optimize grid updates #40
base: main
Are you sure you want to change the base?
Conversation
Many apologies!!! I know it's been almost 3 years since these PRs! I am releasing a new video next week on the overlapping model and did some work to refactor this repository. Would you like to resubmit this? I'm open to incorporating it into the new structure. If you (very understandably) don't have time to look at this again, I'm glad to sort it out! |
instead of going through all cells to get their tile options, we keep a cache of options, and only modify cells that might have changed. Idea: We start from the picked cell, and we check its neighbours. For each neighbour (up, right, down, left), if the list of options has changed, we add its own neighbours to the list of cells to check. If it didn't change, we just skip its neighbours. It is even better than going through the old grid because it propagates changes until we come to a stable state. In the old way, we only check cells once, according to the state at t-1, which can miss some option reductions and lead to infeasibility.
02a127a
to
10966ca
Compare
Hey @shiffman , I solved the conflicts, it's been a while I didn't touch any javascript, but fortunately your changes were small Keep up the good work and the good mood! |
This is great! I'm thinking of doing a follow-up video where I'm go over a whole variety of improvements and incorporate them into the examples. (The new "overlapping model" video is coming out on Tuesday.) I'm going to leave this open for now and link to it from the community contributions in the README. Then when I do the new video I'll go over the code and merge this in! |
Added to the README in #46! |
Instead of going through all cells to get their tile options, we keep the grid (like a cache of options), and only modify cells that might have changed, leaving aside cells we are sure are unchanged.
Idea:
We start from the picked cell, and we check its neighbours. For each neighbour (up, right, down, left), if the list of options has changed, we add its own neighbours to the list of cells to check. If it didn't change, we just skip its neighbours.
It is more accurate than going through the old grid because it propagates changes until we arrive to a stable state.
In the old way, we only check cells once, according to the state at t-1. It seems to me it is reducing the options of the last pick only.
Bonus: since the drawing of cells now a lot of time compared to choosing the next tile, we can have several updates per draw, which speeds considerably the process.
Here with 1 update per tick, DIM = 25, size = 400x400
Here with 10 updates per tick, DIM = 50, size = 800x800
Here with 1000 updates per tick, DIM = 200, size = 800x800