open_pql/functions/
three_flush.rs1use super::*;
2
3#[pqlfn]
4pub fn three_flush(hand: &Hand, street: PQLStreet, board: Board) -> PQLBoolean {
5 n_flush::<3>(hand, board, street)
6}
7
8pub fn n_flush<const N: u8>(
9 hand: &Hand,
10 board: Board,
11 street: PQLStreet,
12) -> PQLBoolean {
13 let c64_hand: Card64 = hand.into();
14 let c64_board: Card64 = (board, street).into();
15
16 for s in Suit::ARR_ALL {
17 let h = c64_hand.count_by_suit(s);
18 if h > 0 {
19 let b = c64_board.count_by_suit(s);
20
21 if h.min(2) + b >= N {
22 return true;
23 }
24 }
25 }
26
27 false
28}
29
30#[cfg(test)]
31pub mod tests {
32 use super::*;
33 use crate::*;
34
35 pub fn has_n_flush(
36 hand: &Hand,
37 board: Board,
38 street: PQLStreet,
39 count_all: usize,
40 ) -> bool {
41 let c64_hand: Card64 = hand.into();
42 let c64_board: Card64 = (board, street).into();
43
44 Suit::ARR_ALL.iter().any(|&s| {
45 let h = c64_hand.count_by_suit(s);
46 let b = c64_board.count_by_suit(s);
47
48 h > 0 && (h.min(2) + b) as usize >= count_all
49 })
50 }
51
52 #[quickcheck]
53 fn test_three_flush(hbg: HandBoardGame) -> TestResult {
54 TestResult::from_bool(
55 has_n_flush(&hbg.hand, hbg.board, hbg.street, 3)
56 == three_flush(hbg.hand.as_ref(), hbg.street, hbg.board),
57 )
58 }
59}