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

Find a more robust way of generating a board #1

Open
meszaros-lajos-gyorgy opened this issue Aug 3, 2023 · 0 comments
Open

Find a more robust way of generating a board #1

meszaros-lajos-gyorgy opened this issue Aug 3, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@meszaros-lajos-gyorgy
Copy link
Owner

Currently the level generation is quite random, I'm essentially keep swapping tiles until I get a solved board. I need to find an algorithm that can generate a board without unnecessary tries.

Current algorithm:

  1. generate a checkerboard pattern
  2. swap 2 tiles randomly 100x times
  3. set number of retries to 10k
  4. keep swapping 2 tiles randomly and after every swap check if the number of incorrect fields is decreasing. If not, then undo swapping and decrease number of retries by 1
  5. if we have a solved pattern then we're good to go, else if the number of retries > 0 then goto 4
  6. if there are no more retries and the board is still not solved, then start over by going to 1

This algorithm gets really slow even at as low as 12x12

@meszaros-lajos-gyorgy meszaros-lajos-gyorgy added the enhancement New feature or request label Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant