mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +00:00
Hearts: Fix sorting for pick_low_points_high_value_card
Previously the function did not sort the hand at all which means we wouldn't necessarily pick the card with the highest value.
This commit is contained in:
parent
63d3beb78c
commit
45117a4134
1 changed files with 5 additions and 7 deletions
|
@ -73,18 +73,16 @@ size_t Player::pick_lead_card(Function<bool(Card&)> valid_play, Function<bool(Ca
|
||||||
|
|
||||||
Optional<size_t> Player::pick_low_points_high_value_card(Optional<Card::Type> type)
|
Optional<size_t> Player::pick_low_points_high_value_card(Optional<Card::Type> type)
|
||||||
{
|
{
|
||||||
|
auto sorted_hand = hand_sorted_by_fn(compare_card_value);
|
||||||
int min_points = -1;
|
int min_points = -1;
|
||||||
Optional<size_t> card_index;
|
Optional<size_t> card_index;
|
||||||
for (ssize_t i = hand.size() - 1; i >= 0; i--) {
|
for (auto& cwi : sorted_hand) {
|
||||||
auto& card = hand[i];
|
if (type.has_value() && cwi.card->type() != type.value())
|
||||||
if (card.is_null())
|
|
||||||
continue;
|
continue;
|
||||||
if (type.has_value() && card->type() != type.value())
|
auto points = hearts_card_points(*cwi.card);
|
||||||
continue;
|
|
||||||
auto points = hearts_card_points(*card);
|
|
||||||
if (min_points == -1 || points < min_points) {
|
if (min_points == -1 || points < min_points) {
|
||||||
min_points = points;
|
min_points = points;
|
||||||
card_index = i;
|
card_index = cwi.index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VERIFY(card_index.has_value() || type.has_value());
|
VERIFY(card_index.has_value() || type.has_value());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue