Slight refactoring

- Remove some duplication in InformationPlayerStrategy::decide()
- Add method GameView::get_other_players()
This commit is contained in:
Felix Bauckholt 2019-02-24 18:49:28 +01:00 committed by Jeff Wu
parent 385feeb6ba
commit b3a8209b74
2 changed files with 18 additions and 25 deletions

View file

@ -451,18 +451,20 @@ pub trait GameView {
}).is_some() }).is_some()
} }
fn can_see(&self, card: &Card) -> bool { fn get_other_players(&self) -> Vec<Player> {
self.get_board().get_players().filter(|&player| { self.get_board().get_players().filter(|&player| {
player != self.me() player != self.me()
}).any(|player| { }).collect()
}
fn can_see(&self, card: &Card) -> bool {
self.get_other_players().iter().any(|player| {
self.has_card(&player, card) self.has_card(&player, card)
}) })
} }
fn someone_else_can_play(&self) -> bool { fn someone_else_can_play(&self) -> bool {
self.get_board().get_players().filter(|&player| { self.get_other_players().iter().any(|player| {
player != self.me()
}).any(|player| {
self.get_hand(&player).iter().any(|card| { self.get_hand(&player).iter().any(|card| {
self.get_board().is_playable(card) self.get_board().is_playable(card)
}) })

View file

@ -462,9 +462,7 @@ impl InformationPlayerStrategy {
} }
fn get_hint_sum_info(&self, total_info: u32, view: &OwnedGameView) -> ModulusInformation { fn get_hint_sum_info(&self, total_info: u32, view: &OwnedGameView) -> ModulusInformation {
view.get_board().get_players().filter(|&player| { view.get_other_players().iter().fold(
player != self.me
}).fold(
ModulusInformation::new(total_info, 0), ModulusInformation::new(total_info, 0),
|mut sum_info, player| { |mut sum_info, player| {
let answer = self.get_hint_info_for_player(&player, total_info, view); let answer = self.get_hint_info_for_player(&player, total_info, view);
@ -1008,24 +1006,15 @@ impl PlayerStrategy for InformationPlayerStrategy {
let public_useless_indices = self.find_useless_cards(view, &self.get_my_public_info()); let public_useless_indices = self.find_useless_cards(view, &self.get_my_public_info());
let useless_indices = self.find_useless_cards(view, &private_info); let useless_indices = self.find_useless_cards(view, &private_info);
if view.board.discard_size() <= soft_discard_threshold { let will_hint =
// if anything is totally useless, discard it if view.board.discard_size() <= soft_discard_threshold && useless_indices.len() > 0 { false }
if public_useless_indices.len() > 1 { // hinting is better than discarding dead cards
let info = self.get_hint_sum_info(public_useless_indices.len() as u32, view); // (probably because it stalls the deck-drawing).
return TurnChoice::Discard(public_useless_indices[info.value as usize]); else if view.board.hints_remaining > 0 && view.someone_else_can_play() { true }
} else if useless_indices.len() > 0 { else { false };
// TODO: have opponents infer that i knew a card was useless
// TODO: after that, potentially prefer useless indices that arent public
return TurnChoice::Discard(useless_indices[0]);
}
}
// hinting is better than discarding dead cards if will_hint {
// (probably because it stalls the deck-drawing). return self.get_hint();
if view.board.hints_remaining > 0 {
if view.someone_else_can_play() {
return self.get_hint();
}
} }
// if anything is totally useless, discard it // if anything is totally useless, discard it
@ -1033,6 +1022,8 @@ impl PlayerStrategy for InformationPlayerStrategy {
let info = self.get_hint_sum_info(public_useless_indices.len() as u32, view); let info = self.get_hint_sum_info(public_useless_indices.len() as u32, view);
return TurnChoice::Discard(public_useless_indices[info.value as usize]); return TurnChoice::Discard(public_useless_indices[info.value as usize]);
} else if useless_indices.len() > 0 { } else if useless_indices.len() > 0 {
// TODO: have opponents infer that i knew a card was useless
// TODO: after that, potentially prefer useless indices that arent public
return TurnChoice::Discard(useless_indices[0]); return TurnChoice::Discard(useless_indices[0]);
} }