Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist. Författare till bok om C64 och senbliven lantis. Röstar pirat.

Startsidan > Texter > Teknikblogg

The new self-contained Hand class


I have added a new class to my poker formation checker (now on .NET 6.0, not 5.0). The library still mainly works with string representations of decks, hands and cards, and the Hand class can be initialized from a string.

// Create a hand from a string:
using Winsoft.Gaming.GenericPokerFormationChecker;
const string handString = "FORMATION=3-OF-A-KIND,SCORE=0333,HAND=CLB04-DMN06-HRTKN*-DMNKN*-SPDKN*";
var hand = new Hand();
Console.WriteLine(hand.Formation); // Output: ThreeOfAKind

But the Hand class can also be initialized using regular function calls.

// Create a hand using the API:
using Winsoft.Gaming.GenericPokerFormationChecker;
var hand = new Hand();
hand.Add(Suit.Spades, Value.Ace);
hand.Add(Suit.Clubs, Value.Ace);
hand.Add(Suit.Diamonds, Value.Ace);
hand.Add(Suit.Hearts, Value.Ace);
hand.Add(Suit.Spades, Value.Value06);
Console.WriteLine(hand.Formation); // FourOfAKind

Also, the Hand class is self contained. You can any time prompt what formation and score it represents, and what cards are included in the formation. If the hand doesn’t have a formation, the InFormation property will point out the highest card.

// Create a hand using the API:
using Winsoft.Gaming.GenericPokerFormationChecker;
var hand = new Hand();
hand.Add(Suit.Hearts, Value.Value10);
hand.Add(Suit.Clubs, Value.Queen);
hand.Add(Suit.Spades, Value.Ace);
hand.Add(Suit.Diamonds, Value.Value03);
hand.Add(Suit.Spades, Value.Value06);
Console.WriteLine(hand[0]!.InFormation); // false
Console.WriteLine(hand[1]!.InFormation); // false
Console.WriteLine(hand[2]!.InFormation); // true
Console.WriteLine(hand[3]!.InFormation); // false
Console.WriteLine(hand[4]!.InFormation); // false

The old API has not changed. Install:

Install-Package PokerFormationChecker

Source code is here, NuGet package is here.

Categories: General

Leave a Reply

Your email address will not be published. Required fields are marked *

En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!


Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.