First Half
This commit is contained in:
parent
ae8c7447db
commit
7ab07edd05
2 changed files with 8 additions and 7 deletions
|
@ -5,6 +5,7 @@ mod rps;
|
||||||
fn main()
|
fn main()
|
||||||
{
|
{
|
||||||
// Checking if the file is found.
|
// Checking if the file is found.
|
||||||
|
let mut score : u64 = 0;
|
||||||
let mut oponent : Vec<String> = read_to_string("input").unwrap().split_whitespace().map(|s| s.to_string()).collect();
|
let mut oponent : Vec<String> = read_to_string("input").unwrap().split_whitespace().map(|s| s.to_string()).collect();
|
||||||
let mut player = oponent.clone();
|
let mut player = oponent.clone();
|
||||||
oponent.retain(|s| s == "A" || s == "B" || s == "C");
|
oponent.retain(|s| s == "A" || s == "B" || s == "C");
|
||||||
|
@ -12,10 +13,10 @@ fn main()
|
||||||
assert!(oponent.len() == player.len(), "Oponent and Player don't play as many turns.");
|
assert!(oponent.len() == player.len(), "Oponent and Player don't play as many turns.");
|
||||||
|
|
||||||
let converter : HashMap<char, rps::RockPaperScissors> = rps::get_converter();
|
let converter : HashMap<char, rps::RockPaperScissors> = rps::get_converter();
|
||||||
let player = converter.get(&'Y').unwrap().battle(converter.get(&'A').unwrap());
|
for tools in oponent.iter().zip(player.iter_mut()) {
|
||||||
println!("First battle = {}", player);
|
let o = tools.0.char_indices().next().unwrap().1;
|
||||||
let player = converter.get(&'X').unwrap().battle(converter.get(&'B').unwrap());
|
let p = tools.1.char_indices().next().unwrap().1;
|
||||||
println!("Second battle = {}", player);
|
score += converter.get(&p).unwrap().battle(converter.get(&o).unwrap());
|
||||||
let player = converter.get(&'Z').unwrap().battle(converter.get(&'C').unwrap());
|
}
|
||||||
println!("Third battle = {}", player);
|
println!("Final score: {}", score);
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue