summaryrefslogtreecommitdiff
path: root/protocol/src/simple_bots.rs
blob: b7986b62f17e290d9def6480055ab85bdc67e416 (plain)
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
use async_trait::async_trait;

use crate::{bot::BiddingBot, bridge_engine::{BiddingStatePlayerView, Bid}};

pub struct AlwaysPassBiddingBot {}

#[async_trait]
impl BiddingBot for AlwaysPassBiddingBot {
    async fn bid(&self, _bidding: &BiddingStatePlayerView) -> Bid {
        Bid::Pass
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use log::info;
    use rand::random;
    use crate::bridge_engine::{BiddingState, Bidding, BiddingStatePlayerView};

    #[tokio::test]
    async fn always_passing_bot_passes() {
        crate::tests::test_setup();
        let dealer = random();
        let player_position = random();
        let bidding_state = BiddingState {
            dealer,
            deal: random(),
            bidding: Bidding::new(dealer),
        };
        let player_view = BiddingStatePlayerView::from_bidding_state(&bidding_state, player_position);
        info!("Bidding state: {bidding_state:#?}");
        assert_eq!(Bid::Pass, (AlwaysPassBiddingBot {}).bid(&player_view).await);
    }
}