add edge cross movement
This commit is contained in:
parent
429f96088d
commit
88a93e9ed7
@ -173,6 +173,7 @@ impl Cube {
|
|||||||
// D
|
// D
|
||||||
|
|
||||||
pub fn u(&mut self) {
|
pub fn u(&mut self) {
|
||||||
|
print!("u");
|
||||||
self.u.rotate();
|
self.u.rotate();
|
||||||
let (f_tr, f_tm, f_tl) = (self.f.tr, self.f.tm, self.f.tl);
|
let (f_tr, f_tm, f_tl) = (self.f.tr, self.f.tm, self.f.tl);
|
||||||
self.f.apply_t(self.r.tl, self.r.tm, self.r.tr);
|
self.f.apply_t(self.r.tl, self.r.tm, self.r.tr);
|
||||||
@ -182,6 +183,7 @@ impl Cube {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn d(&mut self) {
|
pub fn d(&mut self) {
|
||||||
|
print!("d");
|
||||||
self.d.rotate();
|
self.d.rotate();
|
||||||
let (f_br, f_bm, f_bl) = (self.f.br, self.f.bm, self.f.bl);
|
let (f_br, f_bm, f_bl) = (self.f.br, self.f.bm, self.f.bl);
|
||||||
self.f.apply_b(self.l.br, self.l.bm, self.l.bl);
|
self.f.apply_b(self.l.br, self.l.bm, self.l.bl);
|
||||||
@ -191,6 +193,7 @@ impl Cube {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn l(&mut self) {
|
pub fn l(&mut self) {
|
||||||
|
print!("l");
|
||||||
self.l.rotate();
|
self.l.rotate();
|
||||||
let (f_tl, f_ml, f_bl) = (self.f.tl, self.f.ml, self.f.bl);
|
let (f_tl, f_ml, f_bl) = (self.f.tl, self.f.ml, self.f.bl);
|
||||||
self.f.apply_l(self.u.tl, self.u.ml, self.u.bl);
|
self.f.apply_l(self.u.tl, self.u.ml, self.u.bl);
|
||||||
@ -200,6 +203,7 @@ impl Cube {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn r(&mut self) {
|
pub fn r(&mut self) {
|
||||||
|
print!("r");
|
||||||
self.r.rotate();
|
self.r.rotate();
|
||||||
let (f_tr, f_mr, f_br) = (self.f.tr, self.f.mr, self.f.br);
|
let (f_tr, f_mr, f_br) = (self.f.tr, self.f.mr, self.f.br);
|
||||||
self.f.apply_r(self.d.tr, self.d.mr, self.d.br);
|
self.f.apply_r(self.d.tr, self.d.mr, self.d.br);
|
||||||
@ -209,6 +213,7 @@ impl Cube {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn f(&mut self) {
|
pub fn f(&mut self) {
|
||||||
|
print!("f");
|
||||||
self.f.rotate();
|
self.f.rotate();
|
||||||
let (u_bl, u_bm, u_br) = (self.u.bl, self.u.bm, self.u.br);
|
let (u_bl, u_bm, u_br) = (self.u.bl, self.u.bm, self.u.br);
|
||||||
self.u.apply_b(self.l.br, self.l.mr, self.l.tr);
|
self.u.apply_b(self.l.br, self.l.mr, self.l.tr);
|
||||||
@ -218,6 +223,7 @@ impl Cube {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn b(&mut self) {
|
pub fn b(&mut self) {
|
||||||
|
print!("b");
|
||||||
self.b.rotate();
|
self.b.rotate();
|
||||||
let (u_tl, u_tm, u_tr) = (self.u.tl, self.u.tm, self.u.tr);
|
let (u_tl, u_tm, u_tr) = (self.u.tl, self.u.tm, self.u.tr);
|
||||||
self.u.apply_t(self.r.tr, self.r.mr, self.r.br);
|
self.u.apply_t(self.r.tr, self.r.mr, self.r.br);
|
||||||
@ -232,6 +238,7 @@ impl Cube {
|
|||||||
self.u();
|
self.u();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn d2(&mut self) {
|
pub fn d2(&mut self) {
|
||||||
self.d();
|
self.d();
|
||||||
self.d();
|
self.d();
|
||||||
@ -264,6 +271,7 @@ impl Cube {
|
|||||||
self.u();
|
self.u();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn dp(&mut self) {
|
pub fn dp(&mut self) {
|
||||||
self.d();
|
self.d();
|
||||||
self.d();
|
self.d();
|
||||||
|
46
src/f2l.rs
46
src/f2l.rs
@ -57,7 +57,7 @@ fn find_edge(c: &Cube, color_a: Color, color_b: Color) -> Option<(EdgeLoc, EdgeC
|
|||||||
EDGE_LOCS
|
EDGE_LOCS
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&el| (el, get_edge_color(&c, el)))
|
.map(|&el| (el, get_edge_color(&c, el)))
|
||||||
.find(|&(el, ec)| correct_ec(ec))
|
.find(|&(_el, ec)| correct_ec(ec))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
@ -103,17 +103,39 @@ fn move_white_edge_top(c: &mut Cube, el: EdgeLoc, ec: EdgeColor) -> EdgeLoc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn move_edge_cross(c: &mut Cube, el: EdgeLoc, ec: EdgeColor) {}
|
#[rustfmt::skip]
|
||||||
|
fn move_edge_cross(c: &mut Cube, el: EdgeLoc, color: Color) {
|
||||||
fn solve_cross_white_edge(c: &mut Cube, color: Color) {
|
// F = G, B = B, L = R, R = O
|
||||||
// moves the white-<color> edge to the top of the cube with the white
|
let eli: i8 = match el {
|
||||||
// facing the U direction
|
EdgeLoc::UF => 0,
|
||||||
let (el_start, ec) = find_edge(c, Color::W, color).expect("unable to find edge");
|
EdgeLoc::UB => 2,
|
||||||
let el_top = move_white_edge_top(c, el_start, ec);
|
EdgeLoc::UL => 3,
|
||||||
|
EdgeLoc::UR => 1,
|
||||||
|
_ => panic!("invalid edge location: {:?}", el),
|
||||||
|
};
|
||||||
|
let eci: i8 = match color {
|
||||||
|
Color::G => 0,
|
||||||
|
Color::B => 2,
|
||||||
|
Color::R => 3,
|
||||||
|
Color::O => 1,
|
||||||
|
_ => panic!("invalid edge color: {}", color),
|
||||||
|
};
|
||||||
|
let d = (eli - eci + 4) % 4;
|
||||||
|
match d {
|
||||||
|
0 => (),
|
||||||
|
1 => { c.u(); },
|
||||||
|
2 => { c.u2(); },
|
||||||
|
3 => { c.up(); },
|
||||||
|
_ => panic!("invalid d: {}", d)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn solve_cross(_c: &mut Cube) {
|
pub fn solve_cross(c: &mut Cube) {
|
||||||
for color in [Color::G, Color::B, Color::R, Color::O] {}
|
for color in [Color::G, Color::B, Color::R, Color::O] {
|
||||||
|
let (el_start, ec) = find_edge(c, Color::W, color).expect("unable to find edge");
|
||||||
|
let el_top = move_white_edge_top(c, el_start, ec);
|
||||||
|
move_edge_cross(c, el_top, color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn solve_f2l(_c: &mut Cube) {}
|
fn solve_f2l(_c: &mut Cube) {}
|
||||||
@ -122,7 +144,9 @@ fn solve_oll(_c: &mut Cube) {}
|
|||||||
|
|
||||||
fn solve_pll(_c: &mut Cube) {}
|
fn solve_pll(_c: &mut Cube) {}
|
||||||
|
|
||||||
pub fn solve(_c: &mut Cube) {}
|
pub fn solve(c: &mut Cube) {
|
||||||
|
solve_cross(c);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
16
src/main.rs
16
src/main.rs
@ -5,10 +5,20 @@ fn main() {
|
|||||||
let mut c = cube::Cube::new();
|
let mut c = cube::Cube::new();
|
||||||
println!("initial cube:\n{}", c);
|
println!("initial cube:\n{}", c);
|
||||||
|
|
||||||
let moves = cube::parse_moves("R U R' U R U2 R'").expect("unable to parse moves");
|
let moves = cube::parse_moves(
|
||||||
|
"R2 F' D' B D' B2 L' B2 R2 L2 F' B2 L' D B2 U' B' F' D' F2 D2 U' B2 D' B'",
|
||||||
|
)
|
||||||
|
.expect("unable to parse moves");
|
||||||
|
|
||||||
cube::apply_moves(&mut c, moves);
|
cube::apply_moves(&mut c, moves);
|
||||||
|
|
||||||
f2l::solve(&mut c);
|
// TODO: scramble results are wrong
|
||||||
|
println!();
|
||||||
|
println!("after scramble:\n{}", c);
|
||||||
|
|
||||||
println!("after OLL:\n{}", c);
|
f2l::solve_cross(&mut c);
|
||||||
|
|
||||||
|
// TODO: cross is not solved
|
||||||
|
println!();
|
||||||
|
println!("after f2l:\n{}", c);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user