pub struct Algorithm { /* private fields */ }Expand description
Represents a series of moves you can perform on a cube
§Example
use rubiks_moves::moves::Algorithm;
let alg = Algorithm::from("R U R' U'").unwrap();Implementations§
Source§impl Algorithm
impl Algorithm
Sourcepub fn simplify(&self) -> Self
pub fn simplify(&self) -> Self
Creates a shorter set of moves that still leaves the cube in the same state at the end
For example, combining U U into U2, or U U’ into nothing
§Example
use rubiks_moves::moves::Algorithm;
let alg = Algorithm::from("U U").unwrap();
let simplified = Algorithm::from("U2").unwrap();
assert_eq!(alg.simplify(), simplified);Sourcepub fn from(s: &str) -> Result<Self, MoveParseError>
pub fn from(s: &str) -> Result<Self, MoveParseError>
Creates a Algorithm from a &str, mostly a convience function, or a way to take input from the user
§Errors
This errors when it is not given a space seperated list of single face turns e.g. U, F’, or D2
§Example
use rubiks_moves::moves::{Algorithm, Move, FaceTurn};
let parsed_alg = Algorithm::from("F' L").unwrap();Sourcepub fn inverse(&self) -> Self
pub fn inverse(&self) -> Self
Calulates the inverse for a whole algorthm at once.
If a given Algorithm is performed on a cube, then if Algorithm::inverse() is perfermed, the cube will return to its origonal state
§Example
use rubiks_moves::moves::Algorithm;
let original = Algorithm::from("F R U").unwrap();
let inversed = Algorithm::from("U' R' F'").unwrap();
assert_eq!(original.inverse(), inversed);Sourcepub fn sexy() -> Self
pub fn sexy() -> Self
A sample Algorithm that is used often in speedcubing. Equvalent to R U R’ U’
Sourcepub fn order(&self) -> u32
pub fn order(&self) -> u32
Determines how many times an algorithm needs to be repeated, to return to its origonal state
§Example
use rubiks_moves::moves::Algorithm;
let sexy = Algorithm::from("R U R' U'").unwrap();
assert_eq!(sexy.order(), 6);Sourcepub fn solves(&self, other: &Self) -> bool
pub fn solves(&self, other: &Self) -> bool
Determines if an Algorithm solves another one
§Example
use rubiks_moves::moves::Algorithm;
let scramble = Algorithm::from("R' U' F D2 L2 F R2 U2 R2 B D2 L B2 D' B2 L' R' B D2 B U2 L U2 R' U' F").unwrap();
let solution = Algorithm::from("D2 F' D2 U2 F' L2 D R2 D B2 F L2 R' F' D U'").unwrap();
assert!(solution.solves(&scramble));Trait Implementations§
Source§impl IntoIterator for Algorithm
impl IntoIterator for Algorithm
impl Eq for Algorithm
impl StructuralPartialEq for Algorithm
Auto Trait Implementations§
impl Freeze for Algorithm
impl RefUnwindSafe for Algorithm
impl Send for Algorithm
impl Sync for Algorithm
impl Unpin for Algorithm
impl UnsafeUnpin for Algorithm
impl UnwindSafe for Algorithm
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more