From 9ab7d7fcfb252a985c9d8228b67f243f61dca2d6 Mon Sep 17 00:00:00 2001 From: Markus Wagner Date: Fri, 8 Jan 2021 19:04:39 +0100 Subject: [PATCH] Add victory card type --- src/main.rs | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2957784..37fc4ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,7 @@ enum ServerMessage { text: String, }, GameOver { - score: Vec<(usize, usize)>, + score: Vec<(usize, u32)>, }, } @@ -208,22 +208,8 @@ impl Game { (silver(), 40), (gold(), 30), (estate(), victory_qty), - ( - Card { - name: "Duchy".into(), - cost: 5, - types: vec![], - }, - victory_qty, - ), - ( - Card { - name: "Province".into(), - cost: 8, - types: vec![], - }, - victory_qty, - ), + (duchy(), victory_qty), + (province(), victory_qty), ( Card { name: "Curse".into(), @@ -442,15 +428,13 @@ async fn broadcast_state(game: &Game) { .iter() .enumerate() .map(|(i, p)| { - let score = p - .draw_pile - .iter() - .fold(0, |acc, card| match card.name.as_str() { - "Province" => acc + 6, - "Duchery" => acc + 3, - "Estate" => acc + 1, - _ => acc, - }); + let score = p.draw_pile.iter().fold(0, |acc, card| { + if let Some(points) = card.victory() { + acc + points + } else { + acc + } + }); (i, score) }) .sorted_by(|a, b| Ord::cmp(&b.1, &a.1))