feat(game): implement Display trait for MankallaGame

This commit is contained in:
leonhard committed 2026-01-04 20:49:37 +01:00
1 parent 66d2c612ea
commit f235c57a7c
1 file changed
+25
+25
View File
@@ -1,3 +1,5 @@
use std::fmt::Display;
pub struct MankallaGame {
// 13 12 11 10 9 8 7
// 0 1 2 3 4 5 6
@@ -12,6 +14,29 @@ pub enum Player {
Player2,
}
impl Display for MankallaGame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut result: String = "".to_owned();
result.push_str(
self.fields[7..14]
.iter()
.rev()
.map(|field| format!("{:>2}", field))
.collect::<String>()
.as_str(),
);
result.push_str("\n ");
result.push_str(
self.fields[..7]
.iter()
.map(|field| format!("{:>2}", field))
.collect::<String>()
.as_str(),
);
write!(f, "{}", result)
}
}
impl Default for MankallaGame {
fn default() -> Self {
MankallaGame {