Sha256: 267d6494747f30f3e28d2209e28eb430b7bcfb725f7eb762e9edc4975b62a50f
Contents?: true
Size: 1.94 KB
Versions: 2
Compression:
Stored size: 1.94 KB
Contents
module CardsLib module Standard module Rules module Poker def self.precedence [ :royal_flush, :straight_flush, :four_of_a_kind, :full_house, :flush, :straight, :three_of_a_kind, :two_pair, :one_pair, :high_card ] end def self.royal_flush(cards) cards if IsSet.verify(cards, [:suited]) && straight_to_ace(cards) end def self.straight_flush(cards) cards if IsSet.verify(cards, [:unique, :ordered, :suited], {min: 5, max: 5}) end def self.four_of_a_kind(cards) cards if IsSet.verify(cards, [:unique, :paired], {min: 4, max: 4}) end def self.full_house(cards) pair, set = cards.group_by(&:rank).values.sort cards if pair.inject(:pair?) && IsSet.verify(set, [:unique, :paired], {min:3, max: 3}) end def self.flush(cards) cards if IsSet.verify(cards, [:unique, :suited], {min: 5, max: 5}) end def self.straight(cards) cards if IsSet.verify(cards, [:unique, :ordered], {min: 5, max: 5}) || straight_to_ace(cards) end def self.three_of_a_kind(cards) cards if IsSet.verify(cards, [:unique, :paired], {min:3, max: 3}) end def self.two_pair(cards) pair1, pair2 = cards.group_by(&:rank).values.sort cards if pair1.inject(:pair?) && pair2.inject(:pair?) end def self.one_pair(cards) cards if IsSet.verify(cards, [:unique, :paired], {min:2, max: 2}) end def self.high_card(cards) cards.detect {|c| c.rank[/\AA/]} || cards.sort.pop end class << self def straight_to_ace(cards) cards.sort.map(&:rank) == Cards[*%w[As Ks Qs Js Ts]].sort.map(&:rank) end private :straight_to_ace end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cards_lib-0.1.2 | lib/cards_lib/standard/rules/poker.rb |
cards_lib-0.1.1 | lib/cards_lib/standard/rules/poker.rb |