mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:57:45 +00:00
Hearts: Pick better non-matching cards
When we don't have a matching card for the lead card rather than always preferring to play hearts we should try to get rid of our high value cards first if no other player has hearts cards higher than what we have.
This commit is contained in:
parent
4a8d8da46c
commit
8b9da08d5a
3 changed files with 18 additions and 8 deletions
|
@ -107,13 +107,17 @@ Optional<size_t> Player::pick_slightly_higher_value_card(Card& other_card)
|
|||
return {};
|
||||
}
|
||||
|
||||
size_t Player::pick_max_points_card()
|
||||
size_t Player::pick_max_points_card(Function<bool(Card&)> ignore_card)
|
||||
{
|
||||
auto queen_of_spades_maybe = pick_specific_card(Card::Type::Spades, CardValue::Queen);
|
||||
if (queen_of_spades_maybe.has_value())
|
||||
return queen_of_spades_maybe.value();
|
||||
if (has_card_of_type(Card::Type::Hearts))
|
||||
return pick_last_card();
|
||||
if (has_card_of_type(Card::Type::Hearts)) {
|
||||
auto highest_hearts_card_index = pick_last_card();
|
||||
auto& card = hand[highest_hearts_card_index];
|
||||
if (!ignore_card(*card))
|
||||
return highest_hearts_card_index;
|
||||
}
|
||||
return pick_low_points_high_value_card().value();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue