1
0

Finished programming a round.

This commit is contained in:
Florent DENEF 2022-12-02 16:04:40 +01:00
parent fc49a2add1
commit c90d69fdb9

View File

@ -55,10 +55,22 @@ impl Into<i32> for ResultPlay {
}
}
pub fn winning(play: Play) -> char {
match play {
Play::Rock => Play::Paper.into(),
Play::Paper => Play::Scissors.into(),
Play::Scissors => Play::Rock.into(),
pub fn round_score(play: char, counter_play: char) -> i32 {
let coup = Play::from(play); // translate to the play
let counter = Play::from(counter_play); // translate to the play
if coup == counter {
(ResultPlay::Draw as i32) + (counter_play as i32)
} else {
use Play::*;
use ResultPlay::*;
match (&coup, &counter) {
(Rock, Paper) => (Win as i32) + (counter as i32),
(Rock, Scissors) => (Loss as i32) + (counter as i32),
(Paper, Rock) => (Loss as i32) + (counter as i32),
(Paper, Scissors) => (Win as i32) + (counter as i32),
(Scissors, Rock) => (Win as i32) + (counter as i32),
(Scissors, Paper) => (Loss as i32) + (counter as i32),
_ => panic!("Case not covered, impossible to reach."),
}
}
}