add color display, fix r
This commit is contained in:
parent
68cec89b5f
commit
0f0e8005c6
85
Cargo.lock
generated
85
Cargo.lock
generated
@ -2,6 +2,91 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "colored"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cubix"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"colored",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
colored = "2.1.0"
|
||||
|
24
src/main.rs
24
src/main.rs
@ -1,3 +1,4 @@
|
||||
use colored::Colorize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
@ -10,6 +11,19 @@ enum Color {
|
||||
G,
|
||||
}
|
||||
|
||||
impl fmt::Display for Color {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Color::W => write!(f, "{}", "w".white()),
|
||||
Color::Y => write!(f, "{}", "y".yellow()),
|
||||
Color::R => write!(f, "{}", "r".red()),
|
||||
Color::O => write!(f, "{}", "o".magenta()),
|
||||
Color::B => write!(f, "{}", "b".blue()),
|
||||
Color::G => write!(f, "{}", "g".green()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
struct Face {
|
||||
tl: Color,
|
||||
@ -91,7 +105,7 @@ impl fmt::Display for Cube {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
" {:?}{:?}{:?}\n {:?}{:?}{:?}\n {:?}{:?}{:?}\n{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}\n{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}\n{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}{:?}\n {:?}{:?}{:?}\n {:?}{:?}{:?}\n {:?}{:?}{:?}\n",
|
||||
" {}{}{}\n {}{}{}\n {}{}{}\n{}{}{}{}{}{}{}{}{}{}{}{}\n{}{}{}{}{}{}{}{}{}{}{}{}\n{}{}{}{}{}{}{}{}{}{}{}{}\n {}{}{}\n {}{}{}\n {}{}{}\n",
|
||||
self.u.tl, self.u.tm, self.u.tr,
|
||||
self.u.ml, self.u.mm, self.u.mr,
|
||||
self.u.bl, self.u.bm, self.u.br,
|
||||
@ -153,7 +167,7 @@ impl Cube {
|
||||
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.b.apply_l(self.u.br, self.u.mr, self.u.tr);
|
||||
self.u.apply_r(f_tr, f_mr, f_br);
|
||||
}
|
||||
|
||||
@ -216,19 +230,15 @@ impl Cube {
|
||||
fn main() {
|
||||
let mut c = Cube::new();
|
||||
println!("Here's the cube:\n{}", c);
|
||||
// TODO: these rotations are not working right
|
||||
c.r();
|
||||
println!("Here's the cube (after R):\n{}", c);
|
||||
c.u();
|
||||
println!("Here's the cube (after RU):\n{}", c);
|
||||
c.rp();
|
||||
println!("Here's the cube (after RUR'):\n{}", c);
|
||||
c.u();
|
||||
c.r();
|
||||
c.u();
|
||||
c.u();
|
||||
c.rp();
|
||||
println!("Here's the cube:\n{}", c);
|
||||
println!("after OLL:\n{}", c);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Loading…
Reference in New Issue
Block a user