From dbe316d8b337eadff5518585dfc163f2724d0810 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Fri, 30 Dec 2022 10:27:10 -0500 Subject: Utility method to reconstruct Deal from tricks played --- protocol/src/simple_bots.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'protocol/src/simple_bots.rs') diff --git a/protocol/src/simple_bots.rs b/protocol/src/simple_bots.rs index 45d1a5b..182229f 100644 --- a/protocol/src/simple_bots.rs +++ b/protocol/src/simple_bots.rs @@ -46,7 +46,7 @@ impl PlayingBot for RandomPlayingBot { #[cfg(test)] mod tests { use std::str::FromStr; - use crate::move_result::MoveResult; + use crate::{move_result::MoveResult, bridge_engine::SUIT_DISPLAY_ORDER, card::RankOrder}; use super::*; use crate::{ @@ -159,7 +159,9 @@ mod tests { async fn play_until_completion() { crate::tests::test_setup(); let bot = RandomPlayingBot {}; - let mut result = MoveResult::Current(example_play_state()); + let play_state = example_play_state(); + let mut deal = play_state.deal.clone(); + let mut result = MoveResult::Current(play_state); while let MoveResult::Current(play_state) = result { info!("Play state: {play_state:#?}"); let player_state = PlayStatePlayerView::from_play_state( @@ -169,5 +171,13 @@ mod tests { let card = bot.play(&player_state).await; result = play_state.play(card).unwrap(); } + let play_result = result.next().unwrap(); + + // Verify that the deal is intact. + deal.sort(&SUIT_DISPLAY_ORDER, RankOrder::Descending); + let mut result_deal = play_result.deal().into_owned(); + result_deal.sort(&SUIT_DISPLAY_ORDER, RankOrder::Descending); + + assert_eq!(result_deal, deal); } } -- cgit v1.2.3