1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! Fast poker hand analysis: cards and decks, hand ranking, winners and
//! equity for Hold'em, Omaha (4, 5 and 6 cards, hi and hi-lo, bomb pots), stud
//! and draw games, and hand ranges.
//!
//! Cards and decks are `u64` bitfields ([`deck::Deck`]), so set operations and
//! enumerating runouts are cheap. Each game has a state you deal into (players'
//! cards, then the board) and an evaluation that finds the winners, or each
//! player's equity over every way the rest of the board can come.
//!
//! # Winners
//!
//! ```
//! use ducy::deck::Deck;
//! use ducy::games::flop_game::FlopGame;
//! use ducy::games::holdem::{HoldemGameEvaluation, HoldemGameState};
//! use ducy::games::GameEvaluation;
//!
//! let mut game = HoldemGameState::new();
//! game.add_player(Deck::parse("As Ac").unwrap()).unwrap();
//! game.add_player(Deck::parse("Ks Kd").unwrap()).unwrap();
//! game.set_flop(Deck::parse("Kc Qd Js").unwrap()).unwrap();
//!
//! let winners = HoldemGameEvaluation {}.evaluate_winners(&game);
//! assert_eq!(winners[0].player_index(), 1); // a set of kings
//! ```
//!
//! # Equity
//!
//! Every remaining runout is enumerated (in parallel with the default
//! `parallel` feature):
//!
//! ```
//! use ducy::deck::{Card, Deck};
//! use ducy::games::flop_game::FlopGame;
//! use ducy::games::omaha::{OmahaGameEvaluation, OmahaGameState};
//! use ducy::games::GameEquityEvaluation;
//!
//! let mut game = OmahaGameState::new(4);
//! game.add_player(Deck::parse("As Ac Jc Ts").unwrap()).unwrap();
//! game.add_player(Deck::parse("9h 8h 7d 6d").unwrap()).unwrap();
//! game.set_flop(Deck::parse("Jh Th Qd").unwrap()).unwrap();
//! game.set_turn(Card::parse("Jd").unwrap()).unwrap();
//!
//! let equity = OmahaGameEvaluation {}.evaluate_equity(&game);
//! assert_eq!(equity.len(), 2);
//! ```
//!
//! # Ranges
//!
//! Hold'em ranges use the usual notation (`"AQo+, 77+"`, see [`deck::range`]);
//! Omaha ranges use hand classes such as double-suited aces or rundowns (see
//! [`games::omaha_range`]):
//!
//! ```
//! use ducy::games::omaha_range::OmahaRange;
//!
//! let range = OmahaRange::parse("AAxx$ds, $rd$ds", 4).unwrap();
//! assert!(range.coverage() > 0.0 && range.coverage() < 0.05);
//! ```
//!
//! # Features
//!
//! - `parallel` (default): equity over every core, with rayon. Without it,
//! everything still works on one thread (for example in WebAssembly).
//! - `serde`: `Serialize`/`Deserialize` for cards, decks and errors.
//!
//! # Related crates
//!
//! [`ducy-play`](https://docs.rs/ducy-play) plays hands out (blinds, betting,
//! side pots, showdown, tables and bots), built on this crate.
// The README's examples run as doctests, so the ones on crates.io keep working.
;
/// Card, deck, and range primitives using bitfield representation.
/// Custom error types for the library.
/// Game state, evaluation, and equity calculation for poker variants.
/// Hand ranking systems for poker hands.
pub