-
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.
- Loading branch information
Showing
7 changed files
with
217 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod parity; | ||
pub mod phase1; | ||
pub mod phase2; | ||
pub mod scramble; | ||
pub mod wedges; |
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,24 @@ | ||
use cubing::kpuzzle::KPattern; | ||
|
||
use crate::scramble::{ | ||
puzzles::square1::wedges::{WedgeType, NUM_WEDGES, WEDGE_TYPE_LOOKUP}, | ||
randomize::{basic_parity, BasicParity}, | ||
}; | ||
|
||
pub(crate) fn bandaged_wedge_parity(pattern: &KPattern) -> BasicParity { | ||
let wedge_orbit_info = &pattern.kpuzzle().data.ordered_orbit_info[0]; | ||
assert_eq!(wedge_orbit_info.name.0, "WEDGES"); | ||
|
||
let mut bandaged_wedges = Vec::<u8>::default(); | ||
for slot in 0..NUM_WEDGES { | ||
let value = unsafe { | ||
pattern | ||
.packed_orbit_data() | ||
.get_raw_piece_or_permutation_value(wedge_orbit_info, slot) | ||
}; | ||
if WEDGE_TYPE_LOOKUP[value as usize] != WedgeType::CornerUpper { | ||
bandaged_wedges.push(value); | ||
} | ||
} | ||
basic_parity(&bandaged_wedges) | ||
} |
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,86 @@ | ||
use std::fmt::Debug; | ||
|
||
use cubing::kpuzzle::{KPattern, KPuzzle}; | ||
|
||
use crate::{ | ||
_internal::search::{ | ||
check_pattern::PatternValidityChecker, | ||
coordinates::phase_coordinate_puzzle::{PhaseCoordinatePuzzle, SemanticCoordinate}, | ||
}, | ||
scramble::{ | ||
puzzles::{ | ||
mask_pattern::mask, | ||
square1::wedges::{WedgeType, WEDGE_TYPE_LOOKUP}, | ||
}, | ||
randomize::BasicParity, | ||
}, | ||
}; | ||
|
||
use super::{ | ||
super::definitions::square1_square_square_shape_kpattern, parity::bandaged_wedge_parity, | ||
}; | ||
|
||
pub(crate) struct Phase1Checker; | ||
|
||
const SLOTS_THAT_ARE_AFTER_SLICES: [u8; 4] = [0, 6, 12, 18]; | ||
|
||
impl PatternValidityChecker<KPuzzle> for Phase1Checker { | ||
fn is_valid(pattern: &cubing::kpuzzle::KPattern) -> bool { | ||
let orbit_info = &pattern.kpuzzle().data.ordered_orbit_info[0]; | ||
assert_eq!(orbit_info.name.0, "WEDGES"); | ||
|
||
for slot in SLOTS_THAT_ARE_AFTER_SLICES { | ||
let value = unsafe { | ||
pattern | ||
.packed_orbit_data() | ||
.get_raw_piece_or_permutation_value(orbit_info, slot) | ||
}; | ||
|
||
// TODO: consider removing this lookup. We know that the wedge values are only 0, 1, or | ||
// 2 during this phase. | ||
if WEDGE_TYPE_LOOKUP[value as usize] == WedgeType::CornerUpper { | ||
return false; | ||
} | ||
} | ||
|
||
true | ||
} | ||
} | ||
|
||
#[derive(PartialEq, Eq, Hash, Clone)] | ||
pub(crate) struct Square1Phase1CompoundSemanticCoordinate { | ||
masked_pattern: KPattern, | ||
parity: BasicParity, | ||
} | ||
|
||
impl Debug for Square1Phase1CompoundSemanticCoordinate { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("Phase1Coordinates") | ||
.field("masked_pattern", &self.masked_pattern.to_data()) | ||
.field("parity", &self.parity) | ||
.finish() | ||
} | ||
} | ||
|
||
impl SemanticCoordinate<KPuzzle> for Square1Phase1CompoundSemanticCoordinate { | ||
fn try_new(_kpuzzle: &KPuzzle, full_pattern: &KPattern) -> Option<Self> { | ||
let phase_mask = &square1_square_square_shape_kpattern(); // TODO: Store this with the coordinate lookup? | ||
let Ok(masked_pattern) = mask(full_pattern, phase_mask) else { | ||
panic!("Mask application failed"); | ||
}; | ||
|
||
// TODO: this isn't a full validity check for scramble positions. | ||
if !Phase1Checker::is_valid(&masked_pattern) { | ||
return None; | ||
} | ||
|
||
let parity = bandaged_wedge_parity(full_pattern); | ||
Some(Self { | ||
masked_pattern, | ||
parity, | ||
}) | ||
} | ||
} | ||
|
||
pub(crate) type Square1Phase1Puzzle = | ||
PhaseCoordinatePuzzle<KPuzzle, Square1Phase1CompoundSemanticCoordinate>; |
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,55 @@ | ||
use cubing::kpuzzle::KPuzzle; | ||
|
||
use crate::{ | ||
_internal::search::{ | ||
check_pattern::PatternValidityChecker, hash_prune_table::HashPruneTable, | ||
idf_search::SearchOptimizations, | ||
}, | ||
scramble::puzzles::square1::wedges::{WedgeType, WEDGE_TYPE_LOOKUP}, | ||
}; | ||
|
||
struct Phase2Checker; | ||
|
||
impl PatternValidityChecker<KPuzzle> for Phase2Checker { | ||
fn is_valid(pattern: &cubing::kpuzzle::KPattern) -> bool { | ||
let orbit_info = &pattern.kpuzzle().data.ordered_orbit_info[0]; | ||
assert_eq!(orbit_info.name.0, "WEDGES"); | ||
|
||
for slot in [0, 1, 2, 12, 13, 14] { | ||
let value = unsafe { | ||
pattern | ||
.packed_orbit_data() | ||
.get_raw_piece_or_permutation_value(orbit_info, slot) | ||
}; | ||
let wedge_type = &WEDGE_TYPE_LOOKUP[value as usize]; | ||
|
||
if *wedge_type == WedgeType::CornerUpper && (slot == 0 || slot == 12) { | ||
// We can't slice. | ||
return false; | ||
} | ||
|
||
for slot_offset in [3, 6, 9] { | ||
let offset_value = unsafe { | ||
pattern | ||
.packed_orbit_data() | ||
.get_raw_piece_or_permutation_value(orbit_info, slot + slot_offset) | ||
}; | ||
let offset_wedge_type = &WEDGE_TYPE_LOOKUP[offset_value as usize]; | ||
|
||
if wedge_type != offset_wedge_type { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
true | ||
} | ||
} | ||
|
||
struct Square1Phase2Optimizations {} | ||
|
||
impl SearchOptimizations<KPuzzle> for Square1Phase2Optimizations { | ||
type PatternValidityChecker = Phase2Checker; | ||
|
||
type PruneTable = HashPruneTable<KPuzzle, Phase2Checker>; | ||
} |
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,35 @@ | ||
#[derive(PartialEq, Eq)] | ||
pub(crate) enum WedgeType { | ||
CornerLower, | ||
CornerUpper, | ||
Edge, | ||
} | ||
|
||
pub(crate) const NUM_WEDGES: u8 = 24; | ||
|
||
pub(crate) const WEDGE_TYPE_LOOKUP: [WedgeType; NUM_WEDGES as usize] = [ | ||
WedgeType::CornerLower, | ||
WedgeType::CornerUpper, | ||
WedgeType::Edge, | ||
WedgeType::CornerLower, | ||
WedgeType::CornerUpper, | ||
WedgeType::Edge, | ||
WedgeType::CornerLower, | ||
WedgeType::CornerUpper, | ||
WedgeType::Edge, | ||
WedgeType::CornerLower, | ||
WedgeType::CornerUpper, | ||
WedgeType::Edge, | ||
WedgeType::Edge, | ||
WedgeType::CornerLower, | ||
WedgeType::CornerUpper, | ||
WedgeType::Edge, | ||
WedgeType::CornerLower, | ||
WedgeType::CornerUpper, | ||
WedgeType::Edge, | ||
WedgeType::CornerLower, | ||
WedgeType::CornerUpper, | ||
WedgeType::Edge, | ||
WedgeType::CornerLower, | ||
WedgeType::CornerUpper, | ||
]; |
Oops, something went wrong.