1
0

Compare commits

...

3 Commits

Author SHA1 Message Date
Florent DENEF
fc49a2add1 Casting made easy 2022-12-02 15:27:07 +01:00
Florent DENEF
d35a92ed23 Adding results enum for the game. 2022-12-02 15:26:30 +01:00
Florent DENEF
e8b6170797 Changing inputs. 2022-12-02 13:33:01 +01:00
3 changed files with 2528 additions and 7 deletions

2500
prob2.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,16 @@
#[repr(u8)]
#[derive(PartialEq, Eq)]
pub enum Play {
Rock,
Paper,
Scissors,
}
enum ResultPlay {
Win,
Draw,
Loss,
}
impl Into<char> for Play {
fn into(self) -> char {
match self {
@ -25,12 +31,27 @@ impl Into<i32> for Play {
}
}
pub fn translate(letter: char) -> Option<Play> {
match letter {
'A' => Some(Play::Rock),
'B' => Some(Play::Paper),
'C' => Some(Play::Scissors),
_ => None,
impl From<char> for Play {
fn from(letter: char) -> Self {
match letter {
'A' => Play::Rock,
'B' => Play::Paper,
'C' => Play::Scissors,
'X' => Play::Rock,
'Y' => Play::Paper,
'Z' => Play::Scissors,
_ => panic!("Only A, B, C, X, Y or Z letters are available."),
}
}
}
impl Into<i32> for ResultPlay {
fn into(self) -> i32 {
match self {
ResultPlay::Win => 6,
ResultPlay::Draw => 3,
ResultPlay::Loss => 0,
}
}
}