Skip to content

Commit

Permalink
Try to fix up defs (doesn't work yet).
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Feb 4, 2024
1 parent 8ed38eb commit daf400a
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 855 deletions.
5 changes: 4 additions & 1 deletion src/rs/scramble/puzzles/cube4x4x4/four_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ impl Scramble4x4x4FourPhase {
) -> Alg {
let phase1_alg = {
let mut phase1_search_pattern = self.phase1_target_pattern.clone();
dbg!(&main_search_pattern);
// dbg!(&phase1_search_pattern);
for orbit_info in self.kpuzzle.orbit_info_iter() {
for i in 0..orbit_info.num_pieces {
remap_piece_for_phase1_or_phase2_search_pattern(
Expand Down Expand Up @@ -218,7 +220,7 @@ impl Scramble4x4x4FourPhase {

pub(crate) fn scramble_4x4x4(&mut self) -> Alg {
loop {
// let hardcoded_scramble_alg_for_testing = parse_alg!("F' R' B2 D L' B D L2 F L2 F2 B' L2 U2 F2 U2 F' R2 L2 D' L2 Fw2 Rw2 R F' Uw2 U2 Fw2 F Uw2 L U2 R2 D2 Uw U F R F' Rw' Fw B Uw' L' Fw2 F2");
let hardcoded_scramble_alg_for_testing = cubing::alg::parse_alg!("F' R' B2 D L' B D L2 F L2 F2 B' L2 U2 F2 U2 F' R2 L2 D' L2 Fw2 Rw2 R F' Uw2 U2 Fw2 F Uw2 L U2 R2 D2 Uw U F R F' Rw' Fw B Uw' L' Fw2 F2");
// let hardcoded_scramble_alg_for_testing = parse_alg!("2R u");
// let hardcoded_scramble_alg_for_testing =
// parse_alg!("r U2 x r U2 r U2 r' U2 l U2 r' U2 r U2 r' U2 r'");
Expand Down Expand Up @@ -262,6 +264,7 @@ impl Scramble4x4x4FourPhase {
alg_builder.push(&alg_node);
}
let scramble_alg = alg_builder.to_alg();
// let scramble_alg = hardcoded_scramble_alg_for_testing;
let scramble_pattern = random_4x4x4_pattern(Some(&scramble_alg));

if !self.is_valid_scramble_pattern(&scramble_pattern) {
Expand Down
57 changes: 1 addition & 56 deletions src/rs/scramble/puzzles/cube4x4x4/phase2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@ use cubing::{

use crate::{
_internal::{GenericPuzzleCore, ReplacementSolutionCondition, SearchHeuristic},
scramble::{
puzzles::{
cube4x4x4::orbit_info::orbit_info,
definitions::{
cube4x4x4_kpuzzle, cube4x4x4_phase2_target_kpattern,
cube4x4x4_with_wing_parity_kpuzzle,
},
},
randomize::{basic_parity, BasicParity},
},
scramble::randomize::{basic_parity, BasicParity},
};

use super::phase2_symmetry::{Phase2CoordTuple, Phase2Puzzle, Phase2SymmetryTables};
Expand Down Expand Up @@ -91,52 +82,6 @@ enum Phase2EdgeOrientation {
Misoriented,
}

fn calculate_wing_parity(pattern: &KPattern) -> BasicParity {
let wings_orbit_info = orbit_info(pattern.kpuzzle(), 1, "WINGS");
let wing_parity = basic_parity(
&unsafe {
pattern.packed_orbit_data().byte_slice() /* TODO */
}[wings_orbit_info.pieces_or_permutations_offset..wings_orbit_info.orientations_offset],
);
dbg!(&wing_parity);
wing_parity
}

fn set_wing_parity(pattern: &mut KPattern, wing_parity: BasicParity) {
let kpuzzle_clone = pattern.kpuzzle().clone();
let wing_parity_orbit_info = orbit_info(&kpuzzle_clone, 3, "WING_PARITY");
pattern.set_orientation_with_mod(
wing_parity_orbit_info,
0,
&OrientationWithMod {
orientation: wing_parity.into(),
orientation_mod: 0,
},
);
}

pub(crate) fn pattern_to_phase2_pattern(pattern: &KPattern) -> KPattern {
let phase1_kpuzzle = cube4x4x4_kpuzzle();
let phase2_kpuzzle = cube4x4x4_with_wing_parity_kpuzzle();
let phase2_target_pattern = cube4x4x4_phase2_target_kpattern();

let mut new_pattern = phase2_kpuzzle.default_pattern();
for orbit_info in phase1_kpuzzle.orbit_info_iter() {
for i in 0..orbit_info.num_pieces {
remap_piece_for_phase1_or_phase2_search_pattern(
orbit_info,
pattern,
phase2_target_pattern,
&mut new_pattern,
i,
);
}
}

let wing_parity = calculate_wing_parity(pattern);
set_wing_parity(&mut new_pattern, wing_parity);
new_pattern
}
pub(crate) struct Phase2ReplacementSolutionCondition {
pub(crate) checked_patterns_coord: HashSet<Phase2CoordTuple>,
pub(crate) checked_patterns_full: HashSet<KPattern>,
Expand Down
30 changes: 13 additions & 17 deletions src/rs/scramble/puzzles/cube4x4x4/phase2_symmetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ use crate::{
GenericPuzzleCore, MoveTransformationInfo, MoveTransformationMultiples,
PruneTableEntryType, SearchGenerators, SearchHeuristic,
},
scramble::puzzles::definitions::{
cube4x4x4_phase2_target_kpattern, cube4x4x4_with_wing_parity_kpuzzle,
},
scramble::puzzles::{definitions::cube4x4x4_kpuzzle, super_pattern::super_pattern},
};

use cubing::{
alg::{parse_move, AlgParseError, Move},
kpuzzle::{InvalidAlgError, KPattern, KPuzzle, KTransformation},
};

use super::{orbit_info::orbit_info, phase2::pattern_to_phase2_pattern};
use super::orbit_info::orbit_info;

const PHASE1_PRUNE_TABLE_SIZE: usize = 735471; // this is 24 choose 8
const PHASE1_MOVE_COUNT: usize = 33;
Expand Down Expand Up @@ -178,7 +176,7 @@ pub(crate) struct Coord84 {
}

const L_AND_R_CENTER_INDICES: [u8; 8] = [4, 5, 6, 7, 12, 13, 14, 15];
const L_CENTER_PIECE: u8 = 1;
const R_LOWEST_CENTER_PIECE_INDEX: u8 = 8;

impl Coord for Coord84 {
fn coordinate_for_pattern(&self, pattern: &KPattern) -> Phase2Coordinate {
Expand All @@ -189,11 +187,12 @@ impl Coord for Coord84 {
for idx in L_AND_R_CENTER_INDICES {
sum += pattern.get_piece(centers_orbit_info, idx) as u32;
bits *= 2;
if pattern.get_piece(centers_orbit_info, idx) == L_CENTER_PIECE {
if pattern.get_piece(centers_orbit_info, idx) < R_LOWEST_CENTER_PIECE_INDEX {
bits += 1
}
}
if sum != 16 {
if sum != 76 {
dbg!(sum);
panic!("Called coord84 on the wrong kind of kpuzzle");
}
Phase2Coordinate(self.pack84[bits].0)
Expand Down Expand Up @@ -232,14 +231,15 @@ impl Coord for Coord168 {
] {
sum += pattern.get_piece(centers_orbit_info, idx) as u32;
bits *= 2;
if pattern.get_piece(centers_orbit_info, idx) == 0 {
let piece = pattern.get_piece(centers_orbit_info, idx);
if !(4..20).contains(&piece) {
bits += 1
}
}
if bits >= 32768 {
bits = 65535 - bits;
}
if sum != 16 {
if sum != 200 {
panic!("Called coord168 on the wrong kind of kpuzzle");
}
Phase2Coordinate(
Expand Down Expand Up @@ -413,10 +413,9 @@ pub(crate) struct Phase2Puzzle {

impl Phase2Puzzle {
pub(crate) fn coordinate_for_pattern(&self, pattern: &KPattern) -> Phase2CoordTuple {
let phase2_pattern = pattern_to_phase2_pattern(pattern);
Phase2CoordTuple {
c84: self.data.coord_84.coordinate_for_pattern(&phase2_pattern),
c168: self.data.coord_168.coordinate_for_pattern(&phase2_pattern),
c84: self.data.coord_84.coordinate_for_pattern(pattern),
c168: self.data.coord_168.coordinate_for_pattern(pattern),
ep: self.data.coord_ep.coordinate_for_pattern(pattern),
}
}
Expand Down Expand Up @@ -569,10 +568,7 @@ impl Phase2SymmetryTables {
}
}
let mut patterns: Vec<KPattern> = Vec::new();
patterns.push(match coordinate_table {
CoordinateTable::CoordEP => cube4x4x4_with_wing_parity_kpuzzle().default_pattern(), // TODO: can we use this for the others as well?
_ => cube4x4x4_phase2_target_kpattern().clone(),
});
patterns.push(super_pattern(cube4x4x4_kpuzzle()));
let mut patterns_read_idx = 0;
let mut patterns_write_idx = 1;
while patterns_read_idx < patterns_write_idx {
Expand Down Expand Up @@ -612,7 +608,7 @@ impl Phase2SymmetryTables {
algs: vec![],
});
match SearchGenerators::try_new(
cube4x4x4_with_wing_parity_kpuzzle(),
cube4x4x4_kpuzzle(),
&phase2_generators,
&MetricEnum::Hand,
false,
Expand Down
4 changes: 0 additions & 4 deletions src/rs/scramble/puzzles/definitions/4x4x4-Phase2.target.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,5 @@
"orientation": [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
},
"WING_PARITY": {
"pieces": [0],
"orientation": [0]
}
}
Loading

0 comments on commit daf400a

Please sign in to comment.