Skip to content

Commit

Permalink
Upgrade cubing.rs to pick up new parsing macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarron committed Feb 7, 2025
1 parent a26a186 commit ab68f66
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 74 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ license = "MPL-2.0"
edition = "2021"

[workspace.dependencies]
cubing = "0.13.7"
cubing = "0.14.0"

[workspace.metadata.bin]
cbindgen = { version = "0.26.0" }
Expand Down
28 changes: 16 additions & 12 deletions src/rs/examples/2x2x2_three_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,34 @@ pub fn main() {
name: "D orientation".to_owned(),
mask: phase1_kpattern().clone(),
generator_moves: vec![
parse_move!("U"),
parse_move!("L"),
parse_move!("F"),
parse_move!("R"),
parse_move!("B"),
parse_move!("D"),
parse_move!("U").to_owned(),
parse_move!("L").to_owned(),
parse_move!("F").to_owned(),
parse_move!("R").to_owned(),
parse_move!("B").to_owned(),
parse_move!("D").to_owned(),
],
individual_search_options: None,
},
SimpleMaskPhaseInfo {
name: "U orientation".to_owned(),
mask: phase2_kpattern().clone(),
generator_moves: vec![parse_move!("U"), parse_move!("F"), parse_move!("R")],
generator_moves: vec![
parse_move!("U").to_owned(),
parse_move!("F").to_owned(),
parse_move!("R").to_owned(),
],
individual_search_options: None,
},
SimpleMaskPhaseInfo {
name: "PBL".to_owned(),
mask: kpuzzle.default_pattern().clone(),
generator_moves: vec![
parse_move!("U"),
parse_move!("R2"),
parse_move!("F2"),
parse_move!("L2"),
parse_move!("D"),
parse_move!("U").to_owned(),
parse_move!("R2").to_owned(),
parse_move!("F2").to_owned(),
parse_move!("L2").to_owned(),
parse_move!("D").to_owned(),
],
individual_search_options: None,
},
Expand Down
26 changes: 13 additions & 13 deletions src/rs/examples/kociemba_multiphase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ impl KociembaTwoPhase {
name: "G1 reduction".to_owned(),
mask: cube3x3x3_centerless_g1_target_kpattern().clone(),
generator_moves: vec![
parse_move!("U"),
parse_move!("L"),
parse_move!("F"),
parse_move!("R"),
parse_move!("B"),
parse_move!("D"),
parse_move!("U").to_owned(),
parse_move!("L").to_owned(),
parse_move!("F").to_owned(),
parse_move!("R").to_owned(),
parse_move!("B").to_owned(),
parse_move!("D").to_owned(),
],
individual_search_options: None,
},
SimpleMaskPhaseInfo {
name: "Domino".to_owned(),
mask: kpuzzle.default_pattern().clone(),
generator_moves: vec![
parse_move!("U"),
parse_move!("L2"),
parse_move!("F2"),
parse_move!("R2"),
parse_move!("B2"),
parse_move!("D"),
parse_move!("U").to_owned(),
parse_move!("L2").to_owned(),
parse_move!("F2").to_owned(),
parse_move!("R2").to_owned(),
parse_move!("B2").to_owned(),
parse_move!("D").to_owned(),
],
individual_search_options: None,
},
Expand All @@ -67,7 +67,7 @@ pub fn main() {

let scramble = kpuzzle
.default_pattern()
.apply_alg(&parse_alg!(
.apply_alg(parse_alg!(
"F B2 L' U2 D' B2 D B' U2 B2 U2 L2 B2 L2 D B2 U' F2 R2 F2 L"
))
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/rs/experimental_lib_api/gods_algorithm_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use super::common::PatternSource;
/// let depth = table.pattern_to_depth.get(
/// &kpuzzle
/// .default_pattern()
/// .apply_alg(&parse_alg!("F2 B2 D2 L' D L' D L2 F' U2 F' B2 R2 U2 F' D2 F"))
/// .apply_alg(parse_alg!("F2 B2 D2 L' D L' D L2 F' U2 F' B2 R2 U2 F' D2 F"))
/// .unwrap(),
/// );
/// dbg!(depth);
Expand Down
4 changes: 2 additions & 2 deletions src/rs/experimental_lib_api/search_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use super::common::PatternSource;
/// let kpuzzle = cube3x3x3_kpuzzle();
/// let search_pattern = kpuzzle
/// .default_pattern()
/// .apply_alg(&parse_alg!("R U R'"))
/// .apply_alg(parse_alg!("R U R'"))
/// .expect("Invalid alg for puzzle.");
/// let solutions =
/// search(kpuzzle, &search_pattern, Default::default()).expect("Search failed.");
Expand Down Expand Up @@ -97,7 +97,7 @@ mod tests {
let kpuzzle = cube3x3x3_kpuzzle();
let search_pattern = kpuzzle
.default_pattern()
.apply_alg(&parse_alg!("R U R'"))
.apply_alg(parse_alg!("R U R'"))
.expect("Invalid alg for puzzle.");
let mut solutions =
search(kpuzzle, &search_pattern, Default::default()).expect("Search failed.");
Expand Down
28 changes: 16 additions & 12 deletions src/rs/scramble/collapse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fn pop_final_move(nodes: &mut Vec<AlgNode>) -> Option<Move> {
/// - `mod_n`: 4
/// - `mod_offset`: -1
// TODO: `R4` is not collapsed into an empty alg.
// TODO: support taking a reference for cases where that's more efficient?
pub fn collapse_adjacent_moves(alg: Alg, mod_n: i32, mod_offset: i32) -> Alg {
let mut nodes = Vec::<AlgNode>::new();

Expand Down Expand Up @@ -95,35 +96,38 @@ fn collapse_test() {
collapse_adjacent_moves(
parse_alg!(
"R' U' F R2 D U B D U' L' B2 U' F F2 D' B2 D' L2 D' R2 B2 R2 F2 U' B2 D' R' U' F"
),
)
.to_owned(),
4,
-1
),
parse_alg!("R' U' F R2 D U B D U' L' B2 U' F' D' B2 D' L2 D' R2 B2 R2 F2 U' B2 D' R' U' F")
*parse_alg!(
"R' U' F R2 D U B D U' L' B2 U' F' D' B2 D' L2 D' R2 B2 R2 F2 U' B2 D' R' U' F"
)
);

assert_eq!(
collapse_adjacent_moves(parse_alg!("R F F' R"), 4, -1),
parse_alg!("R2")
collapse_adjacent_moves(parse_alg!("R F F' R").to_owned(), 4, -1),
*parse_alg!("R2")
);

assert_eq!(
collapse_adjacent_moves(parse_alg!("R F F2 F R"), 4, -1),
parse_alg!("R2")
collapse_adjacent_moves(parse_alg!("R F F2 F R").to_owned(), 4, -1),
*parse_alg!("R2")
);

assert_eq!(
collapse_adjacent_moves(parse_alg!("U D2 R4 D6' U"), 4, -1),
parse_alg!("U2")
collapse_adjacent_moves(parse_alg!("U D2 R4 D6' U").to_owned(), 4, -1),
*parse_alg!("U2")
);

assert_eq!(
collapse_adjacent_moves(parse_alg!("R F F2 . F R"), 4, -1),
parse_alg!("R F' . F R")
collapse_adjacent_moves(parse_alg!("R F F2 . F R").to_owned(), 4, -1),
*parse_alg!("R F' . F R")
);

assert_eq!(
collapse_adjacent_moves(parse_alg!("R F F2 R"), 5, -2),
parse_alg!("R F2' R")
collapse_adjacent_moves(parse_alg!("R F F2 R").to_owned(), 5, -2),
*parse_alg!("R F2' R")
);
}
20 changes: 10 additions & 10 deletions src/rs/scramble/puzzles/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ pub fn scramble_clock() -> Alg {

// TODO: implement `parse_quantum_move!(…)`?
let back_moves = vec![
parse_move!("U_PLUS_").quantum,
parse_move!("R_PLUS_").quantum,
parse_move!("D_PLUS_").quantum,
parse_move!("L_PLUS_").quantum,
parse_move!("ALL_PLUS_").quantum,
parse_move!("U_PLUS_").quantum.to_owned(),
parse_move!("R_PLUS_").quantum.to_owned(),
parse_move!("D_PLUS_").quantum.to_owned(),
parse_move!("L_PLUS_").quantum.to_owned(),
parse_move!("ALL_PLUS_").quantum.to_owned(),
];

let front_moves = [
back_moves.clone(),
vec![
parse_move!("UR_PLUS_").quantum,
parse_move!("DR_PLUS_").quantum,
parse_move!("DL_PLUS_").quantum,
parse_move!("UL_PLUS_").quantum,
parse_move!("UR_PLUS_").quantum.to_owned(),
parse_move!("DR_PLUS_").quantum.to_owned(),
parse_move!("DL_PLUS_").quantum.to_owned(),
parse_move!("UL_PLUS_").quantum.to_owned(),
],
]
.concat();
Expand All @@ -34,7 +34,7 @@ pub fn scramble_clock() -> Alg {
.into(),
);
}
alg_nodes.push(parse_move!("y2").into());
alg_nodes.push(parse_move!("y2").clone().into());
for back_move in back_moves {
alg_nodes.push(
Move {
Expand Down
8 changes: 4 additions & 4 deletions src/rs/scramble/puzzles/cube3x3x3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ impl Scramble3x3x3TwoPhase {
// For the pre-moves, we don't have to specify R' and U' because we know the FSM only depends on the final `F` move.
// For similar reasons, we only have to specify R' for the post-moves.
(
Some(vec![parse_move!("F")]),
Some(vec![parse_move!("R'")]),
Some(vec![parse_move!("F").to_owned()]),
Some(vec![parse_move!("R'").to_owned()]),
// TODO: support a way to specify a quantum factor
Some(vec![parse_move!("F2'")]),
Some(vec![parse_move!("R2'")]),
Some(vec![parse_move!("F2'").to_owned()]),
Some(vec![parse_move!("R2'").to_owned()]),
)
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/rs/scramble/puzzles/megaminx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pub fn scramble_megaminx() -> Alg {
let mut rng = thread_rng();
let mut alg_nodes = Vec::<AlgNode>::new();

let r_array: [Move; 2] = [parse_move!("R++"), parse_move!("R--")];
let d_array: [Move; 2] = [parse_move!("D++"), parse_move!("D--")];
let u_array: [Move; 2] = [parse_move!("U"), parse_move!("U'")];
let r_array: [&Move; 2] = [parse_move!("R++"), parse_move!("R--")];
let d_array: [&Move; 2] = [parse_move!("D++"), parse_move!("D--")];
let u_array: [&Move; 2] = [parse_move!("U"), parse_move!("U'")];

for _ in 0..NUM_LINES {
let mut random_choice: usize = 0;
Expand Down
8 changes: 3 additions & 5 deletions src/rs/scramble/puzzles/square1/phase2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,8 @@ pub struct Square1Phase2Puzzle {

#[allow(non_snake_case)]
fn square1_tuple(U_SQ_amount: i32, D_SQ_amount: i32) -> Alg {
lazy_static! {
static ref U_SQ_: Move = parse_move!("U_SQ_");
static ref D_SQ_: Move = parse_move!("D_SQ_");
};
let U_SQ_ = parse_move!("U_SQ_");
let D_SQ_ = parse_move!("D_SQ_");

Alg {
nodes: vec![
Expand Down Expand Up @@ -391,7 +389,7 @@ impl Square1Phase2Puzzle {
let full_generator_moves = move_list_from_vec(vec!["U_SQ_", "D_SQ_", "/"]);

let start_pattern = square1_shape_kpattern()
.apply_alg(&parse_alg!("(0, 0)"))
.apply_alg(parse_alg!("(0, 0)"))
.unwrap();
PhaseCoordinatePuzzle::<KPuzzle, Phase2ShapeCoordinate>::new(
kpuzzle.clone(),
Expand Down
10 changes: 5 additions & 5 deletions src/rs/scramble/puzzles/square1/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl Square1Solver {
while let Some(cubing::alg::AlgNode::MoveNode(r#move)) =
phase1_solution.nodes.last()
{
if r#move == &_SLASH_
if r#move == _SLASH_
// TODO: redundant parsing
{
break;
Expand Down Expand Up @@ -238,12 +238,12 @@ fn flush_tuple(
cubing::alg::AlgNode::MoveNode(
current_tuple_U
.take()
.unwrap_or_else(|| parse_move!("U_SQ_0")),
.unwrap_or_else(|| parse_move!("U_SQ_0").to_owned()),
),
cubing::alg::AlgNode::MoveNode(
current_tuple_D
.take()
.unwrap_or_else(|| parse_move!("D_SQ_0")),
.unwrap_or_else(|| parse_move!("D_SQ_0").to_owned()),
),
],
}
Expand All @@ -264,7 +264,7 @@ fn group_square_1_tuples(alg: Alg) -> Alg {
let mut alg_builder = AlgBuilder::default();

#[allow(non_snake_case)]
let U_SQ_0: Move = parse_move!("U_SQ_0");
let U_SQ_0 = parse_move!("U_SQ_0");
#[allow(non_snake_case)]
let D_SQ_0 = parse_move!("D_SQ_0");
#[allow(non_snake_case)]
Expand All @@ -275,7 +275,7 @@ fn group_square_1_tuples(alg: Alg) -> Alg {
let cubing::alg::AlgNode::MoveNode(r#move) = node else {
panic!("Invalid Square-1 scramble alg in internal code.");
};
if r#move == _SLASH_ {
if r#move == *_SLASH_ {
flush_tuple(&mut current_tuple_U, &mut current_tuple_D, &mut alg_builder);

let alg_node: AlgNode = r#move.into();
Expand Down

0 comments on commit ab68f66

Please sign in to comment.