From 5540d1c4c67127abf049537fbb3b67cc90ee4911 Mon Sep 17 00:00:00 2001 From: Felix Bauckholt Date: Wed, 27 Feb 2019 13:20:59 +0100 Subject: [PATCH] Add helper method knows_playable_card --- src/strategies/information.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/strategies/information.rs b/src/strategies/information.rs index eafcd51..46476db 100644 --- a/src/strategies/information.rs +++ b/src/strategies/information.rs @@ -603,6 +603,12 @@ impl InformationPlayerStrategy { info.update_for_hint(&hint.hinted, matches); } + fn knows_playable_card(&self, player: &Player) -> bool { + self.get_player_public_info(&player).iter().any(|table| { + table.probability_is_playable(self.last_view.get_board()) == 1.0 + }) + } + fn someone_else_needs_hint(&self) -> bool { // Does another player have a playable card, but doesn't know it? let view = &self.last_view; @@ -610,10 +616,7 @@ impl InformationPlayerStrategy { let has_playable_card = view.get_hand(&player).iter().any(|card| { view.get_board().is_playable(card) }); - let knows_playable_card = self.get_player_public_info(&player).iter().any(|table| { - table.probability_is_playable(view.get_board()) == 1.0 - }); - has_playable_card && !knows_playable_card + has_playable_card && !self.knows_playable_card(&player) }) } @@ -622,10 +625,7 @@ impl InformationPlayerStrategy { // update accordingly. for player in self.last_view.board.get_players() { if player != self.last_view.board.player { - let knows_playable_card = self.get_player_public_info(&player).iter().any(|table| { - table.probability_is_playable(self.last_view.get_board()) == 1.0 - }); - if !knows_playable_card { + if !self.knows_playable_card(&player) { // If player doesn't know any playable cards, player doesn't have any playable // cards. let mut hand_info = self.take_public_info(&player);