Enum for standard 52-card ranks and extension methods. Rank defines Ace (1) through King (13). RankExtensions provides Short() to get corner label (A,2-10,J,Q,K) and PipCount() returning pip counts for Ace through Ten, zero for face cards.
namespace CardGames;
/// <summary>
/// Card ranks. The numeric value matches the pip count where it makes sense
/// (Ace = 1, Two = 2 ... King = 13). Games decide what each rank is worth.
/// </summary>
public enum Rank
{
Ace = 1,
Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten,
Jack, Queen, King
}
public static class RankExtensions
{
/// <summary>
/// Short label drawn in the card corner (A, 2-10, J, Q, K).
/// </summary>
public static string Short( this Rank rank ) => rank switch
{
Rank.Ace => "A",
Rank.Jack => "J",
Rank.Queen => "Q",
Rank.King => "K",
_ => ((int)rank).ToString()
};
/// <summary>
/// Number of pips to draw in the centre (face cards have none).
/// </summary>
public static int PipCount( this Rank rank ) => rank is >= Rank.Ace and <= Rank.Ten ? (int)rank : 0;
}