use crate::PlayerColor;
#[derive(PartialEq, Debug)]
pub enum GameResult {
Draw,
Decisive(PlayerColor),
}
impl GameResult {
pub fn to_string(result: Option<&Self>) -> String {
let Some(result) = result else {
return String::from("*");
};
match result {
GameResult::Draw => String::from("1/2-1/2"),
GameResult::Decisive(player_color) => match player_color {
PlayerColor::Black => String::from("0-1"),
PlayerColor::White => String::from("1-0"),
},
}
}
pub fn from_string(result: &str) -> Option<GameResult> {
match result {
"1-0" => Some(Self::Decisive(PlayerColor::White)),
"0-1" => Some(Self::Decisive(PlayerColor::Black)),
"1/2-1/2" => Some(Self::Draw),
_ => None,
}
}
}