From 4544d81b7a95f3eb83349b1d247e5b6f2a6012f0 Mon Sep 17 00:00:00 2001 From: Lucas Garron Date: Sat, 14 Sep 2024 16:44:16 -0700 Subject: [PATCH] =?UTF-8?q?Simplify=20`randomize=5Forbit=5Fna=C3=AFve(?= =?UTF-8?q?=E2=80=A6)`=20calls=20for=20now.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All call sites were specifying the orbit manually in the same way anyhow. --- src/rs/scramble/puzzles/cube2x2x2.rs | 4 ++-- src/rs/scramble/puzzles/cube3x3x3.rs | 10 ++++------ src/rs/scramble/puzzles/pyraminx.rs | 10 ++++------ src/rs/scramble/puzzles/skewb.rs | 17 +++++++---------- src/rs/scramble/randomize.rs | 9 +++++++-- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/rs/scramble/puzzles/cube2x2x2.rs b/src/rs/scramble/puzzles/cube2x2x2.rs index 9e2339b..e5abe54 100644 --- a/src/rs/scramble/puzzles/cube2x2x2.rs +++ b/src/rs/scramble/puzzles/cube2x2x2.rs @@ -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, diff --git a/src/rs/scramble/puzzles/cube3x3x3.rs b/src/rs/scramble/puzzles/cube3x3x3.rs index 5c45cc9..f0ee5ee 100644 --- a/src/rs/scramble/puzzles/cube3x3x3.rs +++ b/src/rs/scramble/puzzles/cube3x3x3.rs @@ -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, diff --git a/src/rs/scramble/puzzles/pyraminx.rs b/src/rs/scramble/puzzles/pyraminx.rs index 4763976..fe7bfe9 100644 --- a/src/rs/scramble/puzzles/pyraminx.rs +++ b/src/rs/scramble/puzzles/pyraminx.rs @@ -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, diff --git a/src/rs/scramble/puzzles/skewb.rs b/src/rs/scramble/puzzles/skewb.rs index 647e97b..f45de2a 100644 --- a/src/rs/scramble/puzzles/skewb.rs +++ b/src/rs/scramble/puzzles/skewb.rs @@ -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, }; @@ -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, diff --git a/src/rs/scramble/randomize.rs b/src/rs/scramble/randomize.rs index a5e2699..ca35e6f 100644 --- a/src/rs/scramble/randomize.rs +++ b/src/rs/scramble/randomize.rs @@ -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 { @@ -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 { + // 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) {