GameState::to_string_id

This commit is contained in:
Henri Bourcereau 2024-01-20 21:40:06 +01:00
parent 6fe5a268da
commit 25a5470a12
8 changed files with 206 additions and 298 deletions

View file

@ -23,6 +23,21 @@ impl Dices {
values: (v.0, v.1),
}
}
pub fn to_bits_string(self) -> String {
format!("{:0>3b}{:0>3b}", self.values.0, self.values.1)
}
// pub fn to_bits(self) -> [bool;6] {
// self.to_bits_string().into_bytes().iter().map(|strbit| *strbit == '1' as u8).collect()
// }
// pub from_bits_string(String bits) -> Self {
//
// Dices {
// values: ()
// }
// }
}
/// Trait to roll the dices
@ -42,4 +57,10 @@ mod tests {
assert!(dices.values.1 >= 1 && dices.values.1 <= 6);
}
#[test]
fn test_to_bits_string() {
let dices = Dices { values: (4, 2)};
assert!(dices.to_bits_string() == "100010");
}
}