-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See the comment in `src/rs/scramble/puzzles/skewb.rs` (at https://github.com/cubing/twsearch/pull/58/files#diff-4633898083e67a49d43cbe5d1d3f6c5f84b7be5bf69bc887a39224238635f433) for information about the approach. Co-authored-by: Jeremy Fleischman <[email protected]>
- Loading branch information
Showing
11 changed files
with
221 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/rs/scramble/puzzles/definitions/skewb-fixed-corner-with-co-tweaks.kpuzzle.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
{ | ||
"name": "skewb", | ||
"orbits": [ | ||
{ | ||
"orbitName": "CORNERS1", | ||
"numPieces": 3, | ||
"numOrientations": 3 | ||
}, | ||
{ | ||
"orbitName": "CORNERS2", | ||
"numPieces": 4, | ||
"numOrientations": 3 | ||
}, | ||
{ | ||
"orbitName": "CENTERS", | ||
"numPieces": 6, | ||
"numOrientations": 1 | ||
} | ||
], | ||
"defaultPattern": { | ||
"CORNERS1": { | ||
"pieces": [0, 1, 2], | ||
"orientation": [0, 0, 0], | ||
"orientationMod": [1, 0, 0] | ||
}, | ||
"CORNERS2": { | ||
"pieces": [0, 1, 2, 3], | ||
"orientation": [0, 0, 0, 0], | ||
"orientationMod": [1, 0, 0, 0] | ||
}, | ||
"CENTERS": { | ||
"pieces": [0, 1, 2, 3, 4, 5], | ||
"orientation": [0, 0, 0, 0, 0, 0] | ||
} | ||
}, | ||
"moves": { | ||
"U": { | ||
"CORNERS1": { | ||
"permutation": [0, 1, 2], | ||
"orientationDelta": [0, 0, 1] | ||
}, | ||
"CORNERS2": { | ||
"permutation": [1, 3, 2, 0], | ||
"orientationDelta": [2, 2, 0, 2] | ||
}, | ||
"CENTERS": { | ||
"permutation": [0, 1, 2, 5, 3, 4], | ||
"orientationDelta": [0, 0, 0, 0, 0, 0] | ||
} | ||
}, | ||
"L": { | ||
"CORNERS1": { | ||
"permutation": [0, 1, 2], | ||
"orientationDelta": [1, 0, 0] | ||
}, | ||
"CORNERS2": { | ||
"permutation": [3, 1, 0, 2], | ||
"orientationDelta": [2, 0, 2, 2] | ||
}, | ||
"CENTERS": { | ||
"permutation": [4, 1, 0, 3, 2, 5], | ||
"orientationDelta": [0, 0, 0, 0, 0, 0] | ||
} | ||
}, | ||
"R": { | ||
"CORNERS1": { | ||
"permutation": [0, 1, 2], | ||
"orientationDelta": [0, 1, 0] | ||
}, | ||
"CORNERS2": { | ||
"permutation": [0, 2, 3, 1], | ||
"orientationDelta": [0, 2, 2, 2] | ||
}, | ||
"CENTERS": { | ||
"permutation": [0, 2, 5, 3, 4, 1], | ||
"orientationDelta": [0, 0, 0, 0, 0, 0] | ||
} | ||
}, | ||
"B": { | ||
"CORNERS1": { | ||
"permutation": [2, 0, 1], | ||
"orientationDelta": [2, 2, 2] | ||
}, | ||
"CORNERS2": { | ||
"permutation": [0, 1, 2, 3], | ||
"orientationDelta": [0, 0, 0, 1] | ||
}, | ||
"CENTERS": { | ||
"permutation": [0, 1, 4, 3, 5, 2], | ||
"orientationDelta": [0, 0, 0, 0, 0, 0] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use cubing::alg::Alg; | ||
|
||
use super::{ | ||
super::randomize::{ | ||
randomize_orbit_naïve, OrbitOrientationConstraint, OrbitPermutationConstraint, | ||
}, | ||
super::scramble_search::{filtered_search, generators_from_vec_str}, | ||
definitions::skewb_fixed_corner_with_co_tweaks_kpuzzle, | ||
}; | ||
|
||
pub fn scramble_skewb() -> Alg { | ||
let kpuzzle = skewb_fixed_corner_with_co_tweaks_kpuzzle(); | ||
loop { | ||
let mut scramble_pattern = kpuzzle.default_pattern(); | ||
|
||
/* The total orientation of each corner orbit is constrained by the permutation of the other. | ||
* That is, suppose we have a valid state of Skewb with values labelled as follows: | ||
* | ||
* (Take note of the values highlighted by ↓↓ and ↑↑.) | ||
* | ||
* ↓↓ | ||
* ↓↓ | ||
* { | ||
* "CORNERS1": { "pieces": [@2, @2, @2], "orientation": [#1, @1, @1] }, | ||
* "CORNERS2": { "pieces": [@1, @1, @1, @1], "orientation": [#2, @2, @2, @2]}, | ||
* "CENTERS": { … } | ||
* } ↑↑ | ||
* ↑↑ | ||
* | ||
* Then: | ||
* | ||
* - The orientation of value `#1` is determined by the values labeled `@1`. | ||
* - The orientation of value `#2` is determined by the values labeled `@2`. | ||
* | ||
* Now, we could either: | ||
* | ||
* - Do a bit of math to determine the values `#1` and `#2.` | ||
* - Set the orientations of `#1` and `#2` to "ignored" by using the `orientationMod` feature. | ||
* | ||
* We choose to do the latter with respect to the solved state, then generate a random permutation of this pattern | ||
* (taking into account permutation parity for each orbit) and solve it. In the resulting state: | ||
* | ||
* - All the `@1` values match the solved state, so `#1` must also match the solved state. | ||
* - All the `@2` values match the solved state, so `#2` value also match the solved state. | ||
* | ||
* That is: the entire puzzle is solved, and we can use this to return a uniform random scramble (subject to other filtering). | ||
* | ||
* This approach does not have any performance implications, and also has the benefit that it allows us to randomize each orbit independently. | ||
* | ||
* The numbers check out, as this gives us the following number of distinct states: | ||
* | ||
* | Orbit | Calculation | Number of possibilities | | ||
* |----------|----------------|-------------------------| | ||
* | CORNERS1 | 4! / 2 * 3^3 | 324 | | ||
* | CORNERS2 | 3! / 2 * 3^2 | 27 | | ||
* | CENTERS | 6! / 2 | 360 | | ||
* |----------|----------------|-------------------------| | ||
* | Overall | 324 * 27 * 360 | 3149280 | | ||
* | ||
* This matches: https://www.jaapsch.net/puzzles/skewb.htm | ||
*/ | ||
|
||
let orbit_info = &kpuzzle.data.ordered_orbit_info[0]; | ||
assert_eq!(orbit_info.name.0, "CORNERS1"); | ||
randomize_orbit_naïve( | ||
&mut scramble_pattern, | ||
orbit_info, | ||
OrbitPermutationConstraint::SingleOrbitEvenParity, | ||
OrbitOrientationConstraint::SetPieceZeroToIgnoredOrientation, | ||
); | ||
|
||
let orbit_info = &kpuzzle.data.ordered_orbit_info[1]; | ||
assert_eq!(orbit_info.name.0, "CORNERS2"); | ||
randomize_orbit_naïve( | ||
&mut scramble_pattern, | ||
orbit_info, | ||
OrbitPermutationConstraint::SingleOrbitEvenParity, | ||
OrbitOrientationConstraint::SetPieceZeroToIgnoredOrientation, | ||
); | ||
|
||
let orbit_info = &kpuzzle.data.ordered_orbit_info[2]; | ||
assert_eq!(orbit_info.name.0, "CENTERS"); | ||
randomize_orbit_naïve( | ||
&mut scramble_pattern, | ||
orbit_info, | ||
OrbitPermutationConstraint::SingleOrbitEvenParity, | ||
OrbitOrientationConstraint::OrientationsMustSumToZero, | ||
); | ||
|
||
let generators = generators_from_vec_str(vec!["U", "L", "R", "B"]); // TODO: cache | ||
if let Some(scramble) = filtered_search(&scramble_pattern, generators, 7, Some(11)) { | ||
return scramble; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters