Skip to content

Commit

Permalink
FREEZE.indexed
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Oct 5, 2023
1 parent 803805c commit 20c901c
Showing 1 changed file with 50 additions and 16 deletions.
66 changes: 50 additions & 16 deletions src/rs/search/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ pub struct IDFSearch {
pub scramble_pattern: PackedKPattern,
}

struct SolutionNotFoundInfo {
current_move_class_excluded: bool,
}

#[allow(clippy::derivable_impls)] // Explicitly specify the default.
impl Default for SolutionNotFoundInfo {
fn default() -> Self {
Self {
current_move_class_excluded: false,
}
}
}

enum SearchRecursionResult {
SolutionFound(Alg),
SolutionNotFound(SolutionNotFoundInfo),
}

impl IDFSearch {
pub fn try_new(
packed_kpuzzle: PackedKPuzzle,
Expand All @@ -153,7 +171,7 @@ impl IDFSearch {
prune_table.extend_for_search_depth(remaining_depth);

println!("Searching to depth: {}", remaining_depth);
if let Some(solution) = self.recurse(
if let SearchRecursionResult::SolutionFound(solution) = self.recurse(
&prune_table,
&self.scramble_pattern,
CANONICAL_FSM_START_STATE,
Expand All @@ -176,16 +194,22 @@ impl IDFSearch {
current_pattern: &PackedKPattern,
current_state: CanonicalFSMState,
remaining_depth: usize,
) -> Option<Alg> {
) -> SearchRecursionResult {
if remaining_depth == 0 {
return if current_pattern == &self.target_pattern {
Some(Alg { nodes: vec![] })
SearchRecursionResult::SolutionFound(Alg { nodes: vec![] })
} else {
None
SearchRecursionResult::SolutionNotFound(SolutionNotFoundInfo::default())
};
}
if prune_table.lookup(current_pattern) > remaining_depth {
return None;
let prune_table_depth = prune_table.lookup(current_pattern);
if prune_table_depth > remaining_depth + 1 {
return SearchRecursionResult::SolutionNotFound(SolutionNotFoundInfo {
current_move_class_excluded: true,
});
}
if prune_table_depth > remaining_depth {
return SearchRecursionResult::SolutionNotFound(SolutionNotFoundInfo::default());
}
for (move_class_index, move_transformation_multiples) in
self.search_move_cache.grouped.iter().enumerate()
Expand All @@ -201,23 +225,33 @@ impl IDFSearch {
};

for move_transformation_info in move_transformation_multiples {
if let Some(solution_tail) = self.recurse(
match self.recurse(
prune_table,
&current_pattern.apply_transformation(&move_transformation_info.transformation),
next_state,
remaining_depth - 1,
) {
let mut solution_tail_nodes = solution_tail.nodes;
solution_tail_nodes.insert(
0,
cubing::alg::AlgNode::MoveNode(move_transformation_info.r#move.clone()),
);
return Some(Alg {
nodes: solution_tail_nodes,
});
SearchRecursionResult::SolutionFound(solution_tail) => {
let mut solution_tail_nodes = solution_tail.nodes;
solution_tail_nodes.insert(
0,
cubing::alg::AlgNode::MoveNode(move_transformation_info.r#move.clone()),
);
return SearchRecursionResult::SolutionFound(Alg {
nodes: solution_tail_nodes,
});
}
SearchRecursionResult::SolutionNotFound(SolutionNotFoundInfo {
current_move_class_excluded: true,
}) => {
return SearchRecursionResult::SolutionNotFound(
SolutionNotFoundInfo::default(),
)
}
_ => (),
}
}
}
None
SearchRecursionResult::SolutionNotFound(SolutionNotFoundInfo::default())
}
}

0 comments on commit 20c901c

Please sign in to comment.