Finished programming a round.
This commit is contained in:
parent
fc49a2add1
commit
c90d69fdb9
@ -55,10 +55,22 @@ impl Into<i32> for ResultPlay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn winning(play: Play) -> char {
|
pub fn round_score(play: char, counter_play: char) -> i32 {
|
||||||
match play {
|
let coup = Play::from(play); // translate to the play
|
||||||
Play::Rock => Play::Paper.into(),
|
let counter = Play::from(counter_play); // translate to the play
|
||||||
Play::Paper => Play::Scissors.into(),
|
if coup == counter {
|
||||||
Play::Scissors => Play::Rock.into(),
|
(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."),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user