From 38f8a6aabbfe2378bae1da53ba77344be77f8f56 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 31 May 2021 23:56:13 +0200 Subject: [PATCH] Hearts: Pick better lead cards Previously the AI would prefer playing a lead card for which no other player had a card with a higher value even though it also had a card for which a higher value card was still in play. --- Userland/Games/Hearts/Game.cpp | 5 +---- Userland/Games/Hearts/Player.cpp | 15 ++------------- Userland/Games/Hearts/Player.h | 2 +- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp index a968fde40f6..7be8d6af17f 100644 --- a/Userland/Games/Hearts/Game.cpp +++ b/Userland/Games/Hearts/Game.cpp @@ -327,10 +327,7 @@ size_t Game::pick_card(Player& player) auto prefer_card = [this, &player](Card& card) { return !other_player_has_lower_value_card(player, card) && other_player_has_higher_value_card(player, card); }; - auto lower_value_card_in_play = [this, &player](Card& card) { - return other_player_has_lower_value_card(player, card); - }; - return player.pick_lead_card(move(valid_card), move(prefer_card), move(lower_value_card_in_play)); + return player.pick_lead_card(move(valid_card), move(prefer_card)); } } auto* high_card = &m_trick[0]; diff --git a/Userland/Games/Hearts/Player.cpp b/Userland/Games/Hearts/Player.cpp index c42194734e2..a3d86f82cf5 100644 --- a/Userland/Games/Hearts/Player.cpp +++ b/Userland/Games/Hearts/Player.cpp @@ -39,8 +39,7 @@ Vector Player::hand_sorted_by_points_and_value() const return sorted_hand; } -size_t Player::pick_lead_card(Function valid_play, Function prefer_card, - Function lower_value_card_in_play) +size_t Player::pick_lead_card(Function valid_play, Function prefer_card) { auto sorted_hand = hand_sorted_by_points_and_value(); @@ -51,27 +50,17 @@ size_t Player::pick_lead_card(Function valid_play, Function Player::pick_low_points_high_value_card(Optional type) diff --git a/Userland/Games/Hearts/Player.h b/Userland/Games/Hearts/Player.h index db30a7ef4cd..9f6181e477f 100644 --- a/Userland/Games/Hearts/Player.h +++ b/Userland/Games/Hearts/Player.h @@ -34,7 +34,7 @@ public: } NonnullRefPtrVector pick_cards_to_pass(PassingDirection); - size_t pick_lead_card(Function, Function, Function); + size_t pick_lead_card(Function, Function); Optional pick_low_points_high_value_card(Optional type = {}); Optional pick_lower_value_card(Card& other_card); Optional pick_slightly_higher_value_card(Card& other_card);