1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use super::cards;
use super::points;
use super::pos;
#[derive(Clone, serde::Serialize, Debug)]
pub struct Trick {
pub cards: [Option<cards::Card>; 4],
pub first: pos::PlayerPos,
pub winner: pos::PlayerPos,
}
impl Trick {
pub fn new(first: pos::PlayerPos) -> Self {
Trick {
first,
winner: first,
cards: [None; 4],
}
}
pub fn score(&self, trump: cards::Suit) -> i32 {
self.cards
.iter()
.map(|c| c.map_or(0, |c| points::score(c, trump)))
.sum()
}
pub fn play_card(
&mut self,
player: pos::PlayerPos,
card: cards::Card,
trump: cards::Suit,
) -> bool {
self.cards[player as usize] = Some(card);
if player == self.first {
return false;
}
if points::strength(card, trump)
> points::strength(self.cards[self.winner as usize].unwrap(), trump)
{
self.winner = player
}
player == self.first.prev()
}
pub fn suit(&self) -> Option<cards::Suit> {
self.cards[self.first as usize].map(|c| c.suit())
}
}