百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

ruby-poker

> 编程语言
开源

用于比较扑克手牌并确定胜出者的 Ruby 库。

99 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

用于比较扑克手牌并确定胜出者的 Ruby 库。

= Poker library in Ruby {}[https://travis-ci.org/robolson/ruby-poker]

Author:: {Rob Olson}[https://github.com/robolson] Email:: [first name] [at] thinkingdigitally.com GitHub:: https://github.com/robolson/ruby-poker

== Description

Ruby-Poker handles the logic for getting the rank of a poker hand. It can also be used to compare two or more hands to determine which hand has the highest poker value.

Card representations can be passed to the PokerHand constructor as a string or an array. Face cards (cards ten, jack, queen, king, and ace) are created using their letter representation (T, J, Q, K, A).

== Install

gem install ruby-poker

== Example

require 'rubygems'
require 'ruby-poker'

hand1 = PokerHand.new("8H 9C TC JD QH")
hand2 = PokerHand.new(["3D", "3C", "3S", "KD", "AH"])
puts hand1                => 8h 9c Tc Jd Qh (Straight)
puts hand1.just_cards     => 8h 9c Tc Jd Qh
puts hand1.rank           => Straight
puts hand2                => 3d 3c 3s Kd Ah (Three of a kind)
puts hand2.rank           => Three of a kind
puts hand1 > hand2        => true

== Duplicates

By default ruby-poker will not raise an exception if you add the same card to a hand twice. You can tell ruby-poker to not allow duplicates by doing the following

PokerHand.allow_duplicates = false

Place that line near the beginning of your program. The change is program wide so once allow_duplicates is set to false, all poker hands will raise an exception if a duplicate card is added to the hand.

== Compatibility

Ruby-Poker is compatible with Ruby 1.8, Ruby 1.9, and Ruby 2.X.

== RDoc

View the {generated documentation for ruby-poker}[http://rdoc.info/gems/ruby-poker/frames] on rdoc.info.

== Running test suite

bundle exec rake

There is also a more compreshenive test, testing all permuations of poker hands, but it requires a large data file that must be downloaded first.

bash
wget -P ./test/support/fixtures http://archive.ics.uci.edu/ml/machine-learning-databases/poker/poker-hand-testing.data
bundle exec rake test:integration

== History

In the 0.2.0 release Patrick Hurley's Texas Holdem code from http://www.rubyquiz.com/quiz24.html was merged into ruby-poker.

== License

This is free software; you can redistribute it and/or modify it under the terms of the BSD license. See LICENSE for more details.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言