#poker #hand #hands #card #evaluate #deck #rank

pkr

A library for evaluating poker hands

2 releases

0.1.1 May 31, 2023
0.1.0 May 31, 2023

#5 in #hands

26 downloads per month

GPL-3.0 license

58KB
1K SLoC

pkr

"pkr" is a Rust library that provides basic components to model and evaluate a poker game. It includes basic entities like Card, Rank, Suit, Deck and Hand along with functionalities to shuffle and deal cards. Furthermore it provides a set of tools for creating and evaluating poker hands. The library has been built with efficiency in mind, with performance critical components written in a way to minimize unnecessary computation.

Installation

You can download and use this library in your Rust project by adding the following to your Cargo.toml:

[dependencies]
pkr = "0.1.1"

Features

  • Define poker hands with standard string notation (i.e. "As Ks Qs Js Ts").
  • Evaluate poker hands according to the standard rules of poker, including support for hand types such as Straight Flush, Four of a Kind, Full House, Flush, Straight, Three of a Kind, Two Pair, One Pair and High Card.
  • Calculate the numerical score of a poker hand for comparison.
  • Ability to evaluate poker hands consisting of 2 up to 9 cards.
  • Create a deck consisting of 52 cards and shuffle the deck.

Examples

Create a Hand struct:

use pkr::hand::Hand;
hand1 = Hand::new_from_str("Ts Js Qs Ks As").unwrap();

This creates a Royal Flush hand.

Once you have a Hand you can evaluate its score:

let score1 = hand1.get_score();

This returns an u32 score representing the value of the hand according to the poker rules and makes it comparable:

hand2 = Hand::new_from_str("As Ad Ah Ac Ks").unwrap();
score2 = hand2.get_score();
assert!(score1 > score2);

Please note that this library does not handle game progression (yet) - it simply provides a way to evaluate poker hands.

License

This project is licensed under the GNU General Public License v3.0.

Dependencies

~2MB
~43K SLoC