Skip to content

Commit

Permalink
fixup: some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Apr 24, 2024
1 parent 46e1c10 commit af4b58a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
16 changes: 12 additions & 4 deletions three-style-lib/src/commutator/finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ struct Insertion {
target: Slot,
}

impl Insertion {
fn inserted(&self, state: FaceletCube) -> bool {
state[self.target.current_position] == self.source.value
}

fn first(&self) -> bool {
self.target.initial_position == self.source.value
}
}

#[derive(Debug)]
struct SearchParams<'a> {
state: FaceletCube,
Expand Down Expand Up @@ -155,8 +165,6 @@ impl CommutatorFinder {
}

fn find_insertion(&mut self, params: &SearchParams, interchange: Move, insertion: Insertion) {
let Insertion { source, target } = insertion;

let wrapper_moves = params
.allowed_moves
.iter()
Expand All @@ -176,9 +184,9 @@ impl CommutatorFinder {
let second = first.apply_move(*sm);
let last = second.apply_move(wm.inverse());

if last[target.current_position] == source.value {
if insertion.inserted(last) {
let insertion_first = insertion.first();
let insertion = Alg::new([*wm, *sm, wm.inverse()]);
let insertion_first = target.initial_position == source.value;
self.add_commutator(interchange, insertion, insertion_first);
}
}
Expand Down
3 changes: 1 addition & 2 deletions three-style-lib/src/commutator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
};
use std::fmt;

/// Represents a 3-cycle commutator.
#[derive(Debug, Clone, PartialEq)]
#[allow(clippy::len_without_is_empty)]
pub struct Commutator {
Expand All @@ -21,7 +20,7 @@ impl Commutator {
self.setup.is_none()
}

/// Returns the length og the commutator in its notation form.
/// Returns the length of the commutator in its notation form.
pub fn len(&self) -> usize {
self.setup.as_ref().map_or(0, |s| s.len()) + self.insertion.len() + 1
}
Expand Down
2 changes: 1 addition & 1 deletion three-style-lib/src/facelet/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{

/// State of the cube at the facelet level
/// in the "is replaced by" representation.
/// See https://kociemba.org/cube.htm for more details
/// See https://kociemba.org/cube.htm for more details.
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub struct FaceletCube(FaceletState);

Expand Down
6 changes: 2 additions & 4 deletions three-style-lib/src/moves/alg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ impl Alg {
let mut stack = Vec::new();
let mut group: BTreeMap<MoveKind, Move> = BTreeMap::new();

// First pass, moves should constantly be re-evaluated
// as long as parallelism isn't broken
// First pass, moves should constantly be re-evaluated as long as parallelism isn't broken
for m in self.0 {
let prev_value = group.remove(&m.kind);
let has_prev_value = prev_value.is_some();
Expand All @@ -65,8 +64,7 @@ impl Alg {

moves.extend(group.into_values());

// Second pass, search wide moves generators and reductions
// by trying to reduce move pairs successively
// Second pass, search wide moves reductions by reducing move pairs successively
for m in moves {
let result = stack.last().and_then(|&l| l * m);

Expand Down

0 comments on commit af4b58a

Please sign in to comment.