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

grid construction / initialization cleanup #1

Open
gordonwoodhull opened this issue Sep 29, 2023 · 0 comments
Open

grid construction / initialization cleanup #1

gordonwoodhull opened this issue Sep 29, 2023 · 0 comments

Comments

@gordonwoodhull
Copy link
Owner

gordonwoodhull commented Sep 29, 2023

The core hexapipes system assumes that a grid will be valid after construction.

This is a reasonable assumption for static grids, but works less well for the Penrose grid, which will be selected and generated randomly from an infinite space of possible grids.

To get it working, I split this grid into construction and initialization phases. This allows the grid to be replaced after construction of the grid object, but there is still an extra grid generated and then thrown away – actually two, because both the puzzle instance and the worker construct and then initialize their own grid objects!

This isn't too much of an efficiency concern, but it's messy, and it makes Penrose grids confusing to troubleshoot.

Compounding the problem, gridInfo in grids.js is initialized by constructing an example grid, and is instantiated on both the puzzle and the worker. So that means that a total of four Penrose grids get calculated and then thrown away on the Penrose pages, and two get thrown away on the other pages. An easy solution for this part is to make example grid construction lazy, and I've implemented this successfully in 86e8227, but it's a partial solution.

The correct solution would involve one of:

  1. Always construct and initialize grids separately - a constructed grid would not immediately be valid.
  2. Always wait to construct grids until we know if we have data to initialize them. Cleaner but perhaps requires deeper thought.
@gordonwoodhull gordonwoodhull added this to the merge upstream milestone Sep 29, 2023
gordonwoodhull added a commit that referenced this issue Oct 8, 2023
fixes #9
related to #1 as we were seeing a thrown-away grid compared to saved
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