Expand description
§wiki | A library for handling playing cards and card games.
Last updated October 28, 2024
This crate is part of the OneJoker project
to create free software for handling playing cards and card games
in general, and many poker variants in particular.
Lee Daniel Crocker lee@onejoker.org
Licensed https://creativecommons.org/publicdomain/zero/1.0/
§Example
use onejoker::*;
fn main() -> Result<(), OjError> {
let mut d = Deck::new(DeckType::English).shuffled();
let h1 = d.new_hand().init(d.draw(5));
let h2 = d.new_hand().init(d.draw(5));
println!("Player 1: [{}], Player 2: [{}]", h1, h2);
let eval = HandScale::by_name("poker").eval_full();
let v1 = eval(&h1)?;
let v2 = eval(&h2)?;
if v1 < v2 {
println!("Player 1 wins with [{}]", v1.full_name());
} else if v1 > v2 {
println!("Player 2 wins with [{}]", v2.full_name());
} else {
println!("Players tie with [{}]", v1.full_name());
}
Ok(())
}
This should produce output similar to:
Player 1: [4cJc7s4h6s], Player 2: [Kd6sJdAsKh]
Player 2 wins with [pair of kings, ace, jack, six]
Re-exports§
pub use errors::OjError;
pub use utils::oj_rand_next32;
pub use utils::oj_rand_range;
pub use utils::oj_shuffle;
pub use utils::oj_sort;
pub use utils::oj_next_combination;
pub use utils::oj_binomial;
pub use cards::suit::Suit;
pub use cards::rank::Rank;
pub use cards::card::Card;
pub use cards::card::WHITE_JOKER;
pub use cards::card::BLACK_JOKER;
pub use cards::card::JOKER;
pub use cards::card::LOW_ACE_OF_CLUBS;
pub use cards::card::LOW_ACE_OF_DIAMONDS;
pub use cards::card::LOW_ACE_OF_HEARTS;
pub use cards::card::LOW_ACE_OF_SPADES;
pub use cards::card::DEUCE_OF_CLUBS;
pub use cards::card::DEUCE_OF_DIAMONDS;
pub use cards::card::DEUCE_OF_HEARTS;
pub use cards::card::DEUCE_OF_SPADES;
pub use cards::card::TREY_OF_CLUBS;
pub use cards::card::TREY_OF_DIAMONDS;
pub use cards::card::TREY_OF_HEARTS;
pub use cards::card::TREY_OF_SPADES;
pub use cards::card::FOUR_OF_CLUBS;
pub use cards::card::FOUR_OF_DIAMONDS;
pub use cards::card::FOUR_OF_HEARTS;
pub use cards::card::FOUR_OF_SPADES;
pub use cards::card::FIVE_OF_CLUBS;
pub use cards::card::FIVE_OF_DIAMONDS;
pub use cards::card::FIVE_OF_HEARTS;
pub use cards::card::FIVE_OF_SPADES;
pub use cards::card::SIX_OF_CLUBS;
pub use cards::card::SIX_OF_DIAMONDS;
pub use cards::card::SIX_OF_HEARTS;
pub use cards::card::SIX_OF_SPADES;
pub use cards::card::SEVEN_OF_CLUBS;
pub use cards::card::SEVEN_OF_DIAMONDS;
pub use cards::card::SEVEN_OF_HEARTS;
pub use cards::card::SEVEN_OF_SPADES;
pub use cards::card::EIGHT_OF_CLUBS;
pub use cards::card::EIGHT_OF_DIAMONDS;
pub use cards::card::EIGHT_OF_HEARTS;
pub use cards::card::EIGHT_OF_SPADES;
pub use cards::card::NINE_OF_CLUBS;
pub use cards::card::NINE_OF_DIAMONDS;
pub use cards::card::NINE_OF_HEARTS;
pub use cards::card::NINE_OF_SPADES;
pub use cards::card::TEN_OF_CLUBS;
pub use cards::card::TEN_OF_DIAMONDS;
pub use cards::card::TEN_OF_HEARTS;
pub use cards::card::TEN_OF_SPADES;
pub use cards::card::JACK_OF_CLUBS;
pub use cards::card::JACK_OF_DIAMONDS;
pub use cards::card::JACK_OF_HEARTS;
pub use cards::card::JACK_OF_SPADES;
pub use cards::card::KNIGHT_OF_CLUBS;
pub use cards::card::KNIGHT_OF_DIAMONDS;
pub use cards::card::KNIGHT_OF_HEARTS;
pub use cards::card::KNIGHT_OF_SPADES;
pub use cards::card::QUEEN_OF_CLUBS;
pub use cards::card::QUEEN_OF_DIAMONDS;
pub use cards::card::QUEEN_OF_HEARTS;
pub use cards::card::QUEEN_OF_SPADES;
pub use cards::card::KING_OF_CLUBS;
pub use cards::card::KING_OF_DIAMONDS;
pub use cards::card::KING_OF_HEARTS;
pub use cards::card::KING_OF_SPADES;
pub use cards::card::ACE_OF_CLUBS;
pub use cards::card::ACE_OF_DIAMONDS;
pub use cards::card::ACE_OF_HEARTS;
pub use cards::card::ACE_OF_SPADES;
pub use cards::card_parse::ojc_parse;
pub use cards::deck_type::DeckType;
pub use cards::hashes::ojh_fnv_32;
pub use cards::hashes::ojh_fnv_64;
pub use cards::hashes::ojh_positional_32c;
pub use cards::hashes::ojh_positional_32cs;
pub use cards::hashes::ojh_positional_64c;
pub use cards::hashes::ojh_positional_64cs;
pub use cards::hashes::ojh_bitfield_64co;
pub use cards::hashes::ojh_prime_32cos;
pub use cards::hashes::ojh_prime_64co;
pub use cards::hashes::ojh_prime_64cos;
pub use cards::hashes::ojh_mp5_english;
pub use cards::hashes::ojh_mp5_low;
pub use cards::hashes::ojh_mp4_english;
pub use cards::hashes::ojh_mp4_low;
pub use cards::hashes::ojh_positional_32cs_mp5_low;
pub use cards::hashes::ojh_mp5_stripped;
pub use cards::deck::Deck;
pub use cards::hand::Hand;
pub use poker::hand_scale::HandScale;
pub use poker::hand_evaluation::HandLevel;
pub use poker::hand_evaluation::HandValue;
pub use poker::hand_evaluation::HandEvaluatorFull;
pub use poker::hand_evaluation::HandEvaluatorQuick;
pub use poker::hand_evaluation::ojp_default_hand_value;
pub use poker::hand_evaluation::ojp_best_of;
pub use poker::hand_evaluation::ojp_best_value_of;
pub use poker::hand_evaluation::ojp_default_eval_full;
pub use poker::hand_evaluation::ojp_default_eval_quick;
pub use poker::hand_evaluation::ojp_valid_hand_for_game;
pub use poker::high_hand::ojp_high_full_name;
pub use poker::high_hand::ojp_high_eval_full;
pub use poker::high_hand::ojp_high_eval_quick;
pub use poker::high_hand::ojp_stripped_eval_full;
pub use poker::high_hand::ojp_stripped_eval_quick;
pub use poker::pai_gow::ojp_pai_gow_full_name;
pub use poker::pai_gow::ojp_pai_gow_eval_full_no_bug;
pub use poker::pai_gow::ojp_pai_gow_eval_quick_no_bug;
pub use poker::ace_to_five::ojp_ace_to_five_full_name;
pub use poker::ace_to_five::ojp_ace_to_five_eval_full;
pub use poker::ace_to_five::ojp_ace_to_five_eval_quick;
pub use poker::ace_to_five::ojp_action_razz_full_name;
pub use poker::ace_to_five::ojp_action_razz_eval_full;
pub use poker::ace_to_five::ojp_action_razz_eval_quick;
pub use poker::deuce_to_seven::ojp_deuce_to_seven_full_name;
pub use poker::deuce_to_seven::ojp_deuce_to_seven_eval_full;
pub use poker::deuce_to_seven::ojp_deuce_to_seven_eval_quick;
pub use poker::ace_to_six::ojp_ace_to_six_full_name;
pub use poker::ace_to_six::ojp_ace_to_six_eval_full;
pub use poker::ace_to_six::ojp_ace_to_six_eval_quick;
pub use poker::badugi::ojp_badugi_full_name;
pub use poker::badugi::ojp_badugi_eval_full;
pub use poker::badugi::ojp_badugi_eval_quick;
pub use poker::badugi::ojp_badeucy_eval_full;
pub use poker::badugi::ojp_badeucy_eval_quick;
Modules§
- wiki | Non-game-specific card handling
- wiki | Library-related error types.
- wiki | Poker hands and game play
- wiki | General utility functions
Macros§
- Make const Card object from string. For example,
card!("Ac")
is equivalent to the constantACE_OF_CLUBS
. - Make const array of Card objects from string literals. For example,
cards!("Ac", "2d", "3h")
is equivalent to[ACE_OF_CLUBS, DEUCE_OF_DIAMONDS, TREY_OF_HEARTS]
.