summaryrefslogtreecommitdiff
path: root/protocol/src/simple_bots.rs
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-11-27 16:45:07 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-11-27 17:23:11 -0500
commitd8de16a7187d2a05fd043946cf4cb32449a5aa3b (patch)
tree6c1a212232203dbb6a9da48c192e10bef5d3b932 /protocol/src/simple_bots.rs
parent854f247b6b7bf1106f31d7f23a326c0904d4f87e (diff)
Add basic bot trait for bot bidding
Diffstat (limited to 'protocol/src/simple_bots.rs')
-rw-r--r--protocol/src/simple_bots.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/protocol/src/simple_bots.rs b/protocol/src/simple_bots.rs
new file mode 100644
index 0000000..ffa1be2
--- /dev/null
+++ b/protocol/src/simple_bots.rs
@@ -0,0 +1,35 @@
+use async_trait::async_trait;
+
+use crate::{bot::BiddingBot, bridge_engine::{BiddingStatePlayerView, Bid}};
+
+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::{deal, GameState, 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: deal(),
+ 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);
+ }
+}