|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+use game;
|
|
|
2
|
+use card;
|
|
|
3
|
+
|
|
|
4
|
+pub struct GameScores {
|
|
|
5
|
+ pub attack_score: f32,
|
|
|
6
|
+ pub defense_score: f32,
|
|
|
7
|
+ pub attack_bouts_number: i32,
|
|
|
8
|
+}
|
|
|
9
|
+
|
|
|
10
|
+pub fn compute_game_scores(game: &game::Game) -> GameScores {
|
|
|
11
|
+ let mut game_scores: GameScores = GameScores {
|
|
|
12
|
+ attack_score: 0 as f32,
|
|
|
13
|
+ defense_score: 0 as f32,
|
|
|
14
|
+ attack_bouts_number: 0,
|
|
|
15
|
+ };
|
|
|
16
|
+ for &(card, _) in game.attack_heap.iter() {
|
|
|
17
|
+ game_scores.attack_score += card_score(&card);
|
|
|
18
|
+ match card {
|
|
|
19
|
+ card::Card::Fool |
|
|
|
20
|
+ card::Card::Trump(card::Trump::One) |
|
|
|
21
|
+ card::Card::Trump(card::Trump::TwentyOne) => game_scores.attack_bouts_number += 1,
|
|
|
22
|
+ _ => (),
|
|
|
23
|
+ }
|
|
|
24
|
+ }
|
|
|
25
|
+ for &(card, _) in game.defense_heap.iter() {
|
|
|
26
|
+ game_scores.defense_score += card_score(&card);
|
|
|
27
|
+ }
|
|
|
28
|
+ game_scores
|
|
|
29
|
+}
|
|
|
30
|
+
|
|
|
31
|
+fn card_score(&card: &card::Card) -> f32 {
|
|
|
32
|
+ match card {
|
|
|
33
|
+ card::Card::Face(card::Face { suit: _, symbol }) => {
|
|
|
34
|
+ match symbol {
|
|
|
35
|
+ card::Symbol::Jack => 1.5,
|
|
|
36
|
+ card::Symbol::Knight => 2.5,
|
|
|
37
|
+ card::Symbol::Queen => 3.5,
|
|
|
38
|
+ card::Symbol::King => 4.5,
|
|
|
39
|
+ _ => 0.5,
|
|
|
40
|
+ }
|
|
|
41
|
+ }
|
|
|
42
|
+ card::Card::Fool |
|
|
|
43
|
+ card::Card::Trump(card::Trump::One) |
|
|
|
44
|
+ card::Card::Trump(card::Trump::TwentyOne) => 4.5,
|
|
|
45
|
+ _ => 0.5,
|
|
|
46
|
+ }
|
|
|
47
|
+}
|