#card-game #poker #hand #class #evaluation #hold-em #hand-rank

fudd

Fun with poker. Named after that most famous of rabbit hunters.

4 releases

0.1.9 Jul 3, 2023
0.1.8 Jun 11, 2023
0.1.6 Mar 12, 2023
0.1.4 May 4, 2022
0.1.0 Feb 20, 2022

#69 in Games

GPL-3.0-or-later

280KB
7K SLoC

FUDD

LICENSE Build Status Crates.io Version

🚧 Work In Progress 🚧

Rust poker library. Code inspired by Cactus Kev's work in C. See ckc-rs for the core hand evaluation library which is isolated with no-std for future use in embedded and wasm libraries.

Currently only supports hold'em, but working on Omaha and want to add more types of games. Supporting things like Razz would be a total kick.

Examples

There are several examples of the library in the examples directory, including one that runs through every possible hand combination:

The calc example allows you to do a full analysis of a hand of poker. Here it is running the famous hand quads vs full house between Gus Hansen and Daniel Negreanu on High Stakes Poker:

❯ cargo run --example calc -- -d "6♠ 6♥ 5♦ 5♣" -b "9♣ 6♦ 5♥ 5♠ 8♠"
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/examples/calc -d '6♠ 6♥ 5♦ 5♣' -b '9♣ 6♦ 5♥ 5♠ 8♠'`
Cards Dealt: 6♠ 6♥ 5♦ 5♣ 9♣ 6♦ 5♥ 5♠ 8♠

[Seat 0: 6♠ 6♥, Seat 1: 5♦ 5♣]
[FLOP:  9♣ 6♦ 5♥, TURN:  5♠, RIVER: 8♠]

The Flop: 9♣ 6♦ 5♥
Chances of winning:
Seat #0 6♠ 6♥: 95.7% - CURRENT HAND: 6♠ 6♥ 6♦ 9♣ 5♥ HandRank { value: 2185, name: ThreeOfAKind, class: ThreeSixes }
Seat #1 5♦ 5♣: 6.0% - CURRENT HAND: 5♥ 5♦ 5♣ 9♣ 6♦ HandRank { value: 2251, name: ThreeOfAKind, class: ThreeFives }

The Nuts would be: 9♣ 8♠ 7♠ 6♦ 5♥ HandRank { value: 1605, name: Straight, class: NineHighStraight }

The Turn: 5♠
Chances of winning:
Seat 0: 2.3% - Outs: 6♣
Seat 1: 97.7% - Best Hand: 5♠ 5♥ 5♦ 5♣ 9♣ HandRank { value: 124, name: FourOfAKind, class: FourFives }

The River: 8♠
Seat 0: 0.0%
Seat 1: 100.0%

Winners:
   Seat 1: 5♠ 5♥ 5♦ 5♣ 9♣ HandRank { value: 124, name: FourOfAKind, class: FourFives }

Command:
❯ cargo run --example calc -- -d "6♠ 6♥ 5♦ 5♣" -b "9♣ 6♦ 5♥ 5♠ 8♠"

Add the -n flag and it will add all possible hands at the flop, sorted by strength:

Possible hands at the flop, sorted by strength:
CKC #1605 9♣ 8♠ 7♠ 6♦ 5♥ HandRank { value: 1605, name: Straight, class: NineHighStraight }
CKC #1996 9♠ 9♥ 9♣ 6♦ 5♥ HandRank { value: 1996, name: ThreeOfAKind, class: ThreeNines }
CKC #2185 6♠ 6♥ 6♦ 9♣ 5♥ HandRank { value: 2185, name: ThreeOfAKind, class: ThreeSixes }
CKC #2251 5♠ 5♥ 5♦ 9♣ 6♦ HandRank { value: 2251, name: ThreeOfAKind, class: ThreeFives }
CKC #3047 9♠ 9♣ 6♠ 6♦ 5♥ HandRank { value: 3047, name: TwoPair, class: NinesAndSixes }
CKC #3058 9♠ 9♣ 5♠ 5♥ 6♦ HandRank { value: 3058, name: TwoPair, class: NinesAndFives }
CKC #3221 6♠ 6♦ 5♠ 5♥ 9♣ HandRank { value: 3221, name: TwoPair, class: SixesAndFives }
CKC #3501 A♠ A♥ 9♣ 6♦ 5♥ HandRank { value: 3501, name: Pair, class: PairOfAces }
CKC #3721 K♠ K♥ 9♣ 6♦ 5♥ HandRank { value: 3721, name: Pair, class: PairOfKings }
CKC #3941 Q♠ Q♥ 9♣ 6♦ 5♥ HandRank { value: 3941, name: Pair, class: PairOfQueens }
CKC #4161 J♠ J♥ 9♣ 6♦ 5♥ HandRank { value: 4161, name: Pair, class: PairOfJacks }
CKC #4381 T♠ T♥ 9♣ 6♦ 5♥ HandRank { value: 4381, name: Pair, class: PairOfTens }
CKC #4471 9♠ 9♣ A♠ 6♦ 5♥ HandRank { value: 4471, name: Pair, class: PairOfNines }
CKC #4836 8♠ 8♥ 9♣ 6♦ 5♥ HandRank { value: 4836, name: Pair, class: PairOfEights }
CKC #5056 7♠ 7♥ 9♣ 6♦ 5♥ HandRank { value: 5056, name: Pair, class: PairOfSevens }
CKC #5122 6♠ 6♦ A♠ 9♣ 5♥ HandRank { value: 5122, name: Pair, class: PairOfSixes }
CKC #5342 5♠ 5♥ A♠ 9♣ 6♦ HandRank { value: 5342, name: Pair, class: PairOfFives }
CKC #5720 4♠ 4♥ 9♣ 6♦ 5♥ HandRank { value: 5720, name: Pair, class: PairOfFours }
CKC #5940 3♠ 3♥ 9♣ 6♦ 5♥ HandRank { value: 5940, name: Pair, class: PairOfTreys }
CKC #6160 2♠ 2♥ 9♣ 6♦ 5♥ HandRank { value: 6160, name: Pair, class: PairOfDeuces }
CKC #6305 A♠ K♠ 9♣ 6♦ 5♥ HandRank { value: 6305, name: HighCard, class: AceHigh }
CKC #6753 K♠ Q♠ 9♣ 6♦ 5♥ HandRank { value: 6753, name: HighCard, class: KingHigh }
CKC #7046 Q♠ J♠ 9♣ 6♦ 5♥ HandRank { value: 7046, name: HighCard, class: QueenHigh }
CKC #7227 J♠ T♠ 9♣ 6♦ 5♥ HandRank { value: 7227, name: HighCard, class: JackHigh }
CKC #7346 T♠ 9♣ 8♠ 6♦ 5♥ HandRank { value: 7346, name: HighCard, class: TenHigh }
CKC #7420 9♣ 8♠ 6♦ 5♥ 4♠ HandRank { value: 7420, name: HighCard, class: NineHigh }

Add the -e flag and it will give you the odds of winning at the draw. NOTE this takes a very, very long time (improve me) :

Seat #0 6♠ 6♥: 81.7%
Seat #1 5♦ 5♣: 20.1%

The library is very forgiving with the format of the strings passed in, thanks to my cardpack.rs library:

❯ cargo run --example calc -- -d "AC 4D Kh 6H Kd TH" -b "7C 3D AS 4C 9d"

Other Resources

Dependencies

Example Dependencies

Resources

Dependencies

~12–24MB
~286K SLoC