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

Add bigger puzzles #1

Merged
merged 1 commit into from Jun 19, 2022
Merged

Conversation

shikoba-hn
Copy link
Contributor

Bigger puzzles are added. Three 4x6 and three 6x6. Shortcuts were changed to allow keys for 6 rows. Shuffle generates uniformly a permutation among the reachable states.

puzzle.js Outdated
// checks if odd permutation are possible for that puzzle. It's used
// to fix the state reached when doing a permutation of the puzzle
// during shuffle
isOdd() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems error prone to generate a puzzle with random swaps and then fix it in some cases. What's the advantage over just making a large number of random oves?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was more for the sport than anything else. The two (ridiculous) advantages are performance and choosing uniformly a shuffle. By the way, the actual algorithm can reach only 50% of permutations for odd puzzles because it always do an even number of permutations. Making an additional action on a coin toss would solve that little issue.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the existing easy and medium puzzles, all permutations are reachable. For the existing hard puzzle, only half are reachable. I'd rather we keep the existing shuffle mechanism, speed isn't an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the easy and medium, yes all positions are reachable. But doing 100 moves (or any even number of moves) will never reach the "odd" permutations.

puzzle.js Outdated
return [t, t+1];
rowColGroup(i, h) {
const idx = Math.floor(i / h);
const group = new Array(h);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) you don't need to call new Array(h). You can just do:

const group = [];
for (let j=0; j<h; j++) {
  group[j] = ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. I'm just used to pre-allocate arrays when I can.

@alokmenghrajani
Copy link
Owner

Thanks for the PR. I think the 6x4 don't look aesthetically pleasing. The 6x6 are interesting, let's keep those. I left a few inline comments.

html-ui.js Outdated
this.colorMap = {};
this.colorMap["A"] = "#b7e5dd";
this.colorMap["B"] = "#9a86a4";
this.colorMap["C"] = "#999966";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"#b1bce6" would fit nicely with the other two colors (per https://colorhunt.co/palette/9a86a4b1bce6b7e5ddf1f0c0).

for (let i=0; i<this.cols; i++) {
for (let j=0; j<this.rows; j++) {
const n = j * this.cols + i + 1;
const d = Math.hypot(this.cols - i, this.rows - j) / md;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@shikoba-hn
Copy link
Contributor Author

Thanks for the PR. I think the 6x4 don't look aesthetically pleasing. The 6x6 are interesting, let's keep those. I left a few inline comments.

Thanks for the PR. I think the 6x4 don't look aesthetically pleasing. The 6x6 are interesting, let's keep those. I left a few inline comments.

The main interest of 4x6 was to ensure that no confusion were made between rows/cols and height/width. It's very easy to add or remove a puzzle.

Copy link
Owner

@alokmenghrajani alokmenghrajani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address comments + squash your two commits and we'll be good to merge.

@shikoba-hn
Copy link
Contributor Author

The comments are addressed and the commits are squashed.

@alokmenghrajani
Copy link
Owner

Thanks, sorry for the delay. Going to merge this shortly.

@alokmenghrajani alokmenghrajani merged commit c8ca6a7 into alokmenghrajani:main Jun 19, 2022
@shikoba-hn shikoba-hn deleted the 6x6 branch June 20, 2022 19:07
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

Successfully merging this pull request may close these issues.

None yet

2 participants