8 个版本 (4 个破坏性更新)
0.5.0 | 2023年6月11日 |
---|---|
0.4.1 | 2022年6月28日 |
0.3.0 | 2021年4月24日 |
0.2.2 | 2021年4月13日 |
0.1.0 | 2021年2月13日 |
#481 in 游戏开发
59 每月下载次数
110KB
1.5K SLoC
poker
: 扑克评估crate
poker
是一个用于快速评估和比较扑克牌的Rust crate。它基于 treys
Python包及其中的算法,经过轻微调整和一些个人风格,使其尽可能符合Rust的风格。
use poker::{Evaluator, cards, Card};
fn main() {
// Create a hand evaluator
let eval = Evaluator::new();
// Generate a shuffled deck
let mut deck = Card::generate_shuffled_deck();
// Deal a hand
let hand: Vec<Card> = deck.drain(..5).collect();
// Evaluate
let result = eval.evaluate(hand).expect("Couldn't evaluate hand!");
// Print the hand result
println!("{}", result);
}
使用 poker
将 poker
添加到您的 Cargo.toml
文件中的 dependencies
[dependencies]
poker = "0.5"
功能
poker
目前有两个功能。一个依赖于 rand
crate,以便洗牌生成的牌组。这是默认启用的。
第二个功能,默认不启用,是 static_lookup
。启用此功能将打开 poker::evaluate::static_lookup
模块,其中包含免费的 evauluate
函数。它的工作方式类似于 Evaluator::evaluate
,但从语义上讲,它使用一个不依赖于堆分配的静态数据结构。在幕后,crate在构建时从 另一个仓库 下载数据,因此不需要在运行时构建这个确定性数据。
[dependencies]
# To use without `rand`, add `default-features = false`
poker = { version = "0.5", features = ["static_lookup"] }
关于性能的说明
为了确保 rustc
可以做出适当的内联和优化决策,请记住在发布构建中使用链接时间优化。这会以更慢的编译时间为代价。在您的 Cargo.toml
[profile.release]
# ...
lto = true # the default is false!
示例
poker
包含两个有趣的内置示例: poker-repl
和 jacks-or-better
。 poker-repl
是一个类似于 repl
的环境,您可以在此评估不同的扑克牌手。 jacks-or-better
是 Jacks or Better 视频扑克游戏的终端重现。支付基于 此图像。游戏的规则可以在 这里 找到。
免责声明
jacks-or-better
示例来自poker
仓库,使用了名为credits
的货币进行赌博。此程序仅用于示例目的,以说明此库的一种可能用途。由于可以随时终止和重新启动,因此运行此示例没有风险。请留意真实赌博的财务风险。
您可以通过运行以下命令通过 cargo
安装这些示例
cargo install poker --example=poker-repl
cargo install poker --example=jacks-or-better
# Then you can run the programs, assuming they were installed somewhere in $PATH
poker-repl
jacks-or-better
您还可以通过克隆的 Git 仓库运行示例。
git clone https://github.com/deus-x-mackina/poker.git
cd poker
cargo run --example=poker-repl
cargo run --example=jacks-or-better
许可证
在 MIT 许可证下授权(LICENSE.txt 或 https://open-source.org.cn/licenses/MIT)。
依赖
~0.6–2.2MB
~28K SLoC