Slight refactoring
- Remove some duplication in InformationPlayerStrategy::decide() - Add method GameView::get_other_players()
This commit is contained in:
parent
385feeb6ba
commit
b3a8209b74
2 changed files with 18 additions and 25 deletions
12
src/game.rs
12
src/game.rs
|
@ -451,18 +451,20 @@ pub trait GameView {
|
|||
}).is_some()
|
||||
}
|
||||
|
||||
fn can_see(&self, card: &Card) -> bool {
|
||||
fn get_other_players(&self) -> Vec<Player> {
|
||||
self.get_board().get_players().filter(|&player| {
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
fn someone_else_can_play(&self) -> bool {
|
||||
self.get_board().get_players().filter(|&player| {
|
||||
player != self.me()
|
||||
}).any(|player| {
|
||||
self.get_other_players().iter().any(|player| {
|
||||
self.get_hand(&player).iter().any(|card| {
|
||||
self.get_board().is_playable(card)
|
||||
})
|
||||
|
|
|
@ -462,9 +462,7 @@ impl InformationPlayerStrategy {
|
|||
}
|
||||
|
||||
fn get_hint_sum_info(&self, total_info: u32, view: &OwnedGameView) -> ModulusInformation {
|
||||
view.get_board().get_players().filter(|&player| {
|
||||
player != self.me
|
||||
}).fold(
|
||||
view.get_other_players().iter().fold(
|
||||
ModulusInformation::new(total_info, 0),
|
||||
|mut sum_info, player| {
|
||||
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 useless_indices = self.find_useless_cards(view, &private_info);
|
||||
|
||||
if view.board.discard_size() <= soft_discard_threshold {
|
||||
// if anything is totally useless, discard it
|
||||
if public_useless_indices.len() > 1 {
|
||||
let info = self.get_hint_sum_info(public_useless_indices.len() as u32, view);
|
||||
return TurnChoice::Discard(public_useless_indices[info.value as usize]);
|
||||
} 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]);
|
||||
}
|
||||
}
|
||||
let will_hint =
|
||||
if view.board.discard_size() <= soft_discard_threshold && useless_indices.len() > 0 { false }
|
||||
// hinting is better than discarding dead cards
|
||||
// (probably because it stalls the deck-drawing).
|
||||
else if view.board.hints_remaining > 0 && view.someone_else_can_play() { true }
|
||||
else { false };
|
||||
|
||||
// hinting is better than discarding dead cards
|
||||
// (probably because it stalls the deck-drawing).
|
||||
if view.board.hints_remaining > 0 {
|
||||
if view.someone_else_can_play() {
|
||||
return self.get_hint();
|
||||
}
|
||||
if will_hint {
|
||||
return self.get_hint();
|
||||
}
|
||||
|
||||
// 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);
|
||||
return TurnChoice::Discard(public_useless_indices[info.value as usize]);
|
||||
} 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]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue