Skip to content

Commit

Permalink
Simplify randomize_orbit_naïve(…) calls for now.
Browse files Browse the repository at this point in the history
All call sites were specifying the orbit manually in the same way anyhow.
  • Loading branch information
lgarron committed Sep 14, 2024
1 parent 6e4db75 commit 189d860
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/rs/scramble/puzzles/cube2x2x2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub fn scramble_2x2x2() -> Alg {
*/

let mut scramble_pattern_fixed_corner = kpuzzle.default_pattern();
let orbit_info = &kpuzzle.data.ordered_orbit_info[0];
randomize_orbit_naïve(
&mut scramble_pattern_fixed_corner,
orbit_info,
0,
"CORNERS",
OrbitPermutationConstraint::AnyPermutation,
OrbitOrientationConstraint::OrientationsMustSumToZero,
PieceZeroConstraint::KeepSolved,
Expand Down
10 changes: 4 additions & 6 deletions src/rs/scramble/puzzles/cube3x3x3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,19 @@ impl Default for Scramble3x3x3TwoPhase {
pub fn random_3x3x3_pattern() -> KPattern {
let kpuzzle = cube3x3x3_centerless_kpuzzle();
let mut scramble_pattern = kpuzzle.default_pattern();
let orbit_info = &kpuzzle.data.ordered_orbit_info[0];
assert_eq!(orbit_info.name.0, "EDGES");
let edge_order = randomize_orbit_naïve(
&mut scramble_pattern,
orbit_info,
0,
"EDGES",
OrbitPermutationConstraint::AnyPermutation,
OrbitOrientationConstraint::OrientationsMustSumToZero,
PieceZeroConstraint::AnyPositionAndOrientation,
);
let each_orbit_parity = basic_parity(&edge_order);
let orbit_info = &kpuzzle.data.ordered_orbit_info[1];
assert_eq!(orbit_info.name.0, "CORNERS");
randomize_orbit_naïve(
&mut scramble_pattern,
orbit_info,
1,
"CORNERS",
match each_orbit_parity {
BasicParity::Even => OrbitPermutationConstraint::SingleOrbitEvenParity,
BasicParity::Odd => OrbitPermutationConstraint::SingleOrbitOddParity,
Expand Down
10 changes: 4 additions & 6 deletions src/rs/scramble/puzzles/pyraminx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@ pub fn scramble_pyraminx() -> Alg {
loop {
let mut scramble_pattern = kpuzzle.default_pattern();

let orbit_info = &kpuzzle.data.ordered_orbit_info[0];
assert_eq!(orbit_info.name.0, "EDGES");
randomize_orbit_naïve(
&mut scramble_pattern,
orbit_info,
0,
"EDGES",
OrbitPermutationConstraint::SingleOrbitEvenParity,
OrbitOrientationConstraint::OrientationsMustSumToZero,
PieceZeroConstraint::AnyPositionAndOrientation,
);

let orbit_info = &kpuzzle.data.ordered_orbit_info[1];
assert_eq!(orbit_info.name.0, "CORNERS");
randomize_orbit_naïve(
&mut scramble_pattern,
orbit_info,
1,
"CORNERS",
OrbitPermutationConstraint::IdentityPermutation,
OrbitOrientationConstraint::AnySum,
PieceZeroConstraint::AnyPositionAndOrientation,
Expand Down
17 changes: 7 additions & 10 deletions src/rs/scramble/puzzles/skewb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{
super::randomize::{
randomize_orbit_naïve, OrbitOrientationConstraint, OrbitPermutationConstraint,
},
super::scramble_search::{simple_filtered_search, generators_from_vec_str},
super::scramble_search::{generators_from_vec_str, simple_filtered_search},
definitions::skewb_fixed_corner_with_co_tweaks_kpuzzle,
};

Expand Down Expand Up @@ -62,31 +62,28 @@ pub fn scramble_skewb() -> Alg {
* 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,
0,
"CORNERS1",
OrbitPermutationConstraint::SingleOrbitEvenParity,
OrbitOrientationConstraint::AnySum,
PieceZeroConstraint::IgnoredOrientation,
);

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,
1,
"CORNERS2",
OrbitPermutationConstraint::SingleOrbitEvenParity,
OrbitOrientationConstraint::AnySum,
PieceZeroConstraint::IgnoredOrientation,
);

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,
2,
"CENTERS",
OrbitPermutationConstraint::SingleOrbitEvenParity,
OrbitOrientationConstraint::OrientationsMustSumToZero,
PieceZeroConstraint::AnyPositionAndOrientation,
Expand Down
9 changes: 7 additions & 2 deletions src/rs/scramble/randomize.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cubing::kpuzzle::{KPattern, KPuzzleOrbitInfo, OrientationWithMod};
use cubing::kpuzzle::{KPattern, OrientationWithMod};
use rand::{seq::SliceRandom, thread_rng, Rng};

pub(crate) enum OrbitPermutationConstraint {
Expand Down Expand Up @@ -30,11 +30,16 @@ pub(crate) enum PieceZeroConstraint {
// Returns the piece order
pub(crate) fn randomize_orbit_naïve(
pattern: &mut KPattern,
orbit_info: &KPuzzleOrbitInfo,
orbit_idx: usize,
orbit_name: &str,
permutation_constraints: OrbitPermutationConstraint,
orientation_constraints: OrbitOrientationConstraint,
piece_zero_constraint: PieceZeroConstraint,
) -> Vec<u8> {
// TODO: make it easier to reuse `OrbitInfo` references from a higher level.
let orbit_info = &pattern.kpuzzle().clone().data.ordered_orbit_info[orbit_idx];
assert_eq!(orbit_info.name.0, orbit_name);

let mut rng = thread_rng();
let first_randomized_piece = if matches!(piece_zero_constraint, PieceZeroConstraint::KeepSolved)
{
Expand Down

0 comments on commit 189d860

Please sign in to comment.