1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:57:35 +00:00

LibCards+Games: Replace card "value" int with a Rank enum

Because `card->value() == 11` is a lot less clear than `card->rank() ==
Cards::Rank::Queen`, and also safer.

Put this, along with the `Suit` enum, in the `Cards` namespace directly
instead of inside `Cards::Card`. Slightly less typing that way.
This commit is contained in:
Sam Atkins 2022-08-20 20:21:33 +01:00 committed by Andreas Kling
parent 163a74e3e2
commit aac2488d5c
9 changed files with 121 additions and 75 deletions

View file

@ -31,17 +31,17 @@ enum class CardValue : uint8_t {
inline CardValue hearts_card_value(Card const& card)
{
// Ace has a higher value than all other cards in Hearts
if (card.value() == 0)
if (card.rank() == Cards::Rank::Ace)
return CardValue::Ace;
else
return static_cast<CardValue>(card.value() - 1);
return static_cast<CardValue>(to_underlying(card.rank()) - 1);
}
inline uint8_t hearts_card_points(Card const& card)
{
if (card.suit() == Card::Suit::Hearts)
if (card.suit() == Cards::Suit::Hearts)
return 1;
else if (card.suit() == Card::Suit::Spades && hearts_card_value(card) == CardValue::Queen)
else if (card.suit() == Cards::Suit::Spades && hearts_card_value(card) == CardValue::Queen)
return 13;
else
return 0;