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
Conversation
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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] = ...
}
There was a problem hiding this comment.
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.
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"; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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. |
There was a problem hiding this 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.
The comments are addressed and the commits are squashed. |
Thanks, sorry for the delay. Going to merge this shortly. |
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.