summaryrefslogtreecommitdiff
path: root/Userland/Games/Hearts
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-09-28 11:35:12 +0100
committerSam Atkins <atkinssj@gmail.com>2022-10-10 16:16:01 +0100
commit46299f385314196d9e527068c46a7ce3712bb115 (patch)
tree1d69b65448607dfe7e53312bab3049d5edca633e /Userland/Games/Hearts
parent1d533acbc0c87a7c5084af066677217b16d1334b (diff)
downloadserenity-46299f385314196d9e527068c46a7ce3712bb115.zip
LibCards+Games: Move "create a deck" logic to LibCards
`create_standard_deck()` is the usual 52-card deck, but more custom setups (such as Spider's multiples-of-one-suit) can be created by passing suit counts to `create_deck()`.
Diffstat (limited to 'Userland/Games/Hearts')
-rw-r--r--Userland/Games/Hearts/Game.cpp12
1 files changed, 2 insertions, 10 deletions
diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp
index a792c0647c..1207d6d21b 100644
--- a/Userland/Games/Hearts/Game.cpp
+++ b/Userland/Games/Hearts/Game.cpp
@@ -199,20 +199,12 @@ void Game::setup(String player_name, int hand_number)
m_passing_button->set_focus(false);
}
- NonnullRefPtrVector<Card> deck;
- deck.ensure_capacity(Card::card_count * 4);
-
- for (int i = 0; i < Card::card_count; ++i) {
- deck.append(Card::construct(Cards::Suit::Clubs, static_cast<Cards::Rank>(i)));
- deck.append(Card::construct(Cards::Suit::Spades, static_cast<Cards::Rank>(i)));
- deck.append(Card::construct(Cards::Suit::Hearts, static_cast<Cards::Rank>(i)));
- deck.append(Card::construct(Cards::Suit::Diamonds, static_cast<Cards::Rank>(i)));
- }
+ NonnullRefPtrVector<Card> deck = Cards::create_standard_deck(Cards::Shuffle::Yes);
for (auto& player : m_players) {
player.hand.ensure_capacity(Card::card_count);
for (uint8_t i = 0; i < Card::card_count; ++i) {
- auto card = deck.take(get_random_uniform(deck.size()));
+ auto card = deck.take_last();
if constexpr (!HEARTS_DEBUG) {
if (&player != &m_players[0])
card->set_upside_down(true);