oceanSimple.OPokerCommon 1.0.1

dotnet add package oceanSimple.OPokerCommon --version 1.0.1
                    
NuGet\Install-Package oceanSimple.OPokerCommon -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="oceanSimple.OPokerCommon" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="oceanSimple.OPokerCommon" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="oceanSimple.OPokerCommon" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add oceanSimple.OPokerCommon --version 1.0.1
                    
#r "nuget: oceanSimple.OPokerCommon, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package oceanSimple.OPokerCommon@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=oceanSimple.OPokerCommon&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=oceanSimple.OPokerCommon&version=1.0.1
                    
Install as a Cake Tool

♾️Getting started

💫Description

This project introduces a TexasDeck class, which comprises 52 OPokerCard objects (organized as 4 colors of 13 numbers each). You can utilize the TexasDeck.Draw method to draw a specified number (n) of OPokerCard objects. If you are developing a Texas Hold'em project, the OPokerHandler utility can be employed to convert OPokerCard objects into Hand objects. Subsequently, you can compare these Hand objects to determine their relative rankings.

💫Prerequisites

.NET 8

💫Running

A basic example:

using OPokerCommon;
using OPokerCommon.Decks;

// Get the deck of cards
var deck = new TexasDeck();
deck.Shuffle();

// Draw 7 cards from the deck
var cards1 = deck.Draw(7);
var cards2 = deck.Draw(7);
Console.WriteLine($"Card1: {string.Join(", ", cards1.Select(c => c.ToString()))}");
Console.WriteLine($"Card2: {string.Join(", ", cards2.Select(c => c.ToString()))}");

// Convert cards to Hand
var handler = OPokerHandler.Instance;
var hand1 = handler.GetHand(cards1);
var hand2 = handler.GetHand(cards2);
Console.WriteLine($"Hand1: {hand1}");
Console.WriteLine($"Hand2: {hand2}");

// Compare two hands
var result = handler.CompareTwoHands(hand1, hand2);
Console.WriteLine($"Result: {result}");

The running result: ( The result is random ! )

Card1: ♠5, ♠8, ♥8, ♣4, ♥K, ♠Q, ♣K
Card2: ♦8, ♣7, ♣2, ♠4, ♠6, ♣9, ♦2
Hand1: ♥K ♣K ♠Q ♠8 ♥8
Hand2: ♣9 ♦8 ♣7 ♣2 ♦2
Result: 1

♾️OPokerHandler

public interface IOPokerHandler {
    /// <summary>
    ///     Compare two hands. <br />
    /// </summary>
    /// <returns>
    ///     1: hand1 > hand2 <br />
    ///     0: hand1 = hand2 <br />
    ///     -1: hand1 less than  hand2  <br />
    /// </returns>
    int CompareTwoHands(Hand hand1, Hand hand2);

    /// <summary>
    ///     Get the max hands' index from the given hands. <br />
    /// </summary>
    /// <returns>
    ///     A list of max hands' index from the given hands. <br />
    /// </returns>
    List<int> GetMaxHands(List<Hand> hands);

    /// <summary>
    ///     Sorts the cards by their number in descending order.
    /// </summary>
    /// <param name="cards">The cards that need to be sorted</param>
    void SortCardsByNumber(List<OPokerCard> cards);

    /// <summary>
    ///     Sorts the cards by their color in ascending order. <br />
    ///     If two cards have the same color, they are sorted by their number in descending order.
    /// </summary>
    /// <param name="cards">The cards that need to be sorted</param>
    void SortCardsByColor(List<OPokerCard> cards);

    /// <summary>
    ///     Get the deck of cards. <br />
    /// </summary>
    /// <returns></returns>
    TexasDeck GetDeck();

    /// <summary>
    ///     Get the card by its color and number. <br />
    /// </summary>
    /// <returns></returns>
    OPokerCard GetCard(int color, int number);

    /// <summary>
    ///     Get the hand from the given cards. <br />
    /// </summary>
    /// <returns></returns>
    Hand GetHand(List<OPokerCard> cards);
}

♾️OPokerCard

💫OPokerCard

public class OPokerCard {
    public OPokerCard(int colorCode, int numberCode) {
        Color = new CardColor(colorCode);
        Number = new CardNumber(numberCode);
    }

    public CardColor Color { get; set; }
    public CardNumber Number { get; set; }
}

💫CardColor

Code Description Picture
0 Spade ♠
1 Heart ♥
2 Diamond ♦
3 Club ♣
4 Red Red
5 Black Black
[method: JsonConstructor]
public class CardColor(int code, string description, string picture) {
    public int Code { get; set; } = code;
    public string Description { get; set; } = description;
    public string Picture { get; set; } = picture;

    public int CompareTo(CardColor other) {
        return Code.CompareTo(other.Code);
    }
}

💫CardNumber

Code Value Description Picture
1 14 Ace A
2 2 Two 2
3 3 Three 3
4 4 Four 4
5 5 Five 5
6 6 Six 6
7 7 Seven 7
8 8 Eight 8
9 9 Nine 9
10 10 Ten 10
11 11 Jack J
12 12 Queen Q
13 13 King K
14 15 Joker Joker
[method: JsonConstructor]
public class CardNumber(int code, int value, string description, string picture) {
    public int Code { get; set; } = code;
    public int Value { get; set; } = value;
    public string Description { get; set; } = description;
    public string Picture { get; set; } = picture;

    public int CompareTo(CardNumber other) {
        return Value.CompareTo(other.Value);
    }
}

♾️TexasDeck

TexasDeck has 4 x 13 cards.

public interface IDeck {
    /// <summary>
    ///     Sort the deck by color and number. <br />
    ///     Sort by the color code and number value, so A is the biggest card.
    /// </summary>
    public void Sort();

    /// <summary>
    ///     Shuffle the deck. <br />
    /// </summary>
    public void Shuffle();

    /// <summary>
    ///     Draw n card from the deck. <br />
    ///     If the deck has less than n cards, it will draw all the cards in the deck. <br />
    /// </summary>
    public List<OPokerCard> Draw(int count);
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 209 5/20/2025
1.0.0 203 5/20/2025