Compare commits

...

2 Commits

Author SHA1 Message Date
Michael Peters
fdd22cd531 add r 2024-03-12 14:10:23 -07:00
Michael Peters
3e2381f42a add d and l 2024-03-12 14:05:00 -07:00

View File

@ -87,12 +87,12 @@ struct Cube {
impl Cube {
fn new() -> Self {
Self {
u: Face::new(Color::W),
d: Face::new(Color::Y),
u: Face::new(Color::Y),
d: Face::new(Color::W),
l: Face::new(Color::R),
r: Face::new(Color::O),
b: Face::new(Color::B),
f: Face::new(Color::G),
b: Face::new(Color::B),
}
}
// U
@ -107,6 +107,33 @@ impl Cube {
self.b.apply_t(self.l.tr, self.l.tm, self.l.tl);
self.l.apply_t(f_tr, f_tm, b_tl);
}
fn d(&mut self) {
self.d.rotate();
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.l.apply_b(self.b.br, self.b.bm, self.b.bl);
self.b.apply_b(self.r.br, self.r.bm, self.r.bl);
self.r.apply_b(f_br, f_bm, f_bl);
}
fn l(&mut self) {
self.l.rotate();
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.u.apply_l(self.b.br, self.b.mr, self.b.tr);
self.b.apply_r(self.d.bl, self.d.ml, self.d.tl);
self.d.apply_l(f_tl, f_ml, f_bl);
}
fn r(&mut self) {
self.r.rotate();
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.d.apply_r(self.b.bl, self.b.ml, self.b.tl);
self.b.apply_l(self.u.br, self.u.mr, self.u.tl);
self.u.apply_r(f_tr, f_mr, f_br);
}
}
fn main() {
@ -121,11 +148,47 @@ mod tests {
fn test_u() {
let mut c = Cube::new();
c.u();
assert_eq!(c.d, Face::new(Color::Y));
assert_eq!(c.u, Face::new(Color::Y));
assert_eq!(c.f.tr, Color::O);
assert_eq!(c.l.tr, Color::G);
assert_eq!(c.b.tr, Color::R);
assert_eq!(c.r.tr, Color::B);
assert_eq!(c.u, Face::new(Color::W));
assert_eq!(c.d, Face::new(Color::W));
}
#[test]
fn test_d() {
let mut c = Cube::new();
c.d();
assert_eq!(c.d, Face::new(Color::W));
assert_eq!(c.f.br, Color::R);
assert_eq!(c.l.br, Color::B);
assert_eq!(c.b.br, Color::O);
assert_eq!(c.r.br, Color::G);
assert_eq!(c.u, Face::new(Color::Y));
}
#[test]
fn test_l() {
let mut c = Cube::new();
c.l();
assert_eq!(c.l, Face::new(Color::R));
assert_eq!(c.f.bl, Color::Y);
assert_eq!(c.d.bl, Color::G);
assert_eq!(c.b.br, Color::W);
assert_eq!(c.u.bl, Color::B);
assert_eq!(c.r, Face::new(Color::O));
}
#[test]
fn test_r() {
let mut c = Cube::new();
c.r();
assert_eq!(c.r, Face::new(Color::O));
assert_eq!(c.f.br, Color::W);
assert_eq!(c.d.br, Color::B);
assert_eq!(c.b.bl, Color::Y);
assert_eq!(c.u.br, Color::G);
assert_eq!(c.l, Face::new(Color::R));
}
}