From 1b33595091334bb17db78298cad4eefa7b448c22 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 20 Jan 2023 23:14:32 +0300 Subject: feat: implement Display for Bitboard --- src/main.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.rs b/src/main.rs index e7a11a9..822f773 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,22 @@ +use std::fmt; + +struct Bitboard(u64); + +impl fmt::Display for Bitboard { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + for index in (0..64) { + f.write_str(if (&self.0 >> index & 1 == 1) { "1" } else { "." }); + if ((index + 1) % 8 == 0) { + f.write_str("\n"); + } + } + return write!(f, "\n") + } +} + fn main() { + const bb:Bitboard = Bitboard(33); println!("Hello, world!"); + println!("{}", bb); + println!("{}", bb.0); } -- cgit v1.2.3