Giter Site home page Giter Site logo

poker's Introduction

= poker

  A library for constructing and comparing poker hands.
  It also provides a deck of cards.

== Usage

  Cards can be constructed using a suit and a face, a suit and a value, or a short representation of a card.

    # The Ace of Spades
    Card.new('Spades', 'Ace') ==
    Card.new('Spades', 14) ==
    Card.new('As')

    # The 8 of Hearts
    Card.new('Hearts', '8') ==
    Card.new('Hearts', 8) ==
    Card.new('8h')

  Card#to_s gives the short representation of a card 

    Card.new('Clubs', '7').to_s == '7c'
    Card.new('Diamonds', 'King').to_s == 'Kd'

  Hands can be constructed using any combination of cards, string representations of cards, and other hands.

    Hand.new(Card.new('As'), 'Ah Kd Qc', Card.new('Qh'))
    Hand.new(Card.new('As'), Hand.new('Ah Kd'), 'Qc', Card.new('Qh'))

  Hand#to_s gives the short representation of a hand

    hand = Hand.new(Card.new('As'), 'Ah Kd Qc', Card.new('Qh'))
    hand.to_s # 'As Ah Kd Qc Qh' or similar (card order is not guaranteed)

  Hands can be compared to each other.

    # two pair beats one pair
    Hand.new('As Ac Kh Qd Qc') > Hand.new('5s 5s 9c 3h 7d') # true

    # flush beats a straight
    Hand.new('7h 2h Jh Th 8h') > Hand.new('6s 7c 8d 9s Tc') # true

    # only the best 5-card hand is considered
    Hand.new('Jc Qh Kd Ks Ah Ac') == Hand.new('Tc Qh Kd Ks Ah Ac') # true

  A number of properties can be asked about a hand.

    # each method returns true or false
    straight_flush?
    quads?
    full_house?
    flush?
    straight?
    set?
    two_pair?
    pair?
    four_to_flush?
    open_ended?
    gutshot?
    double_gutshot?

  A deck can provide cards to play with.

    deck = Deck.new
    while playing do
      deck.shuffle
      player_cards = [Deck.next(2), Deck.next(2)]
      board_cards = Deck.next(3) # flop
      board_cards += Deck.next(1) # turn
      board_cards += Deck.next(1) # river
      winning_hand = player_cards.map{ |p| Hand.new *(p + board_cards) }.sort.first
    end

poker's People

Contributors

bakineggs avatar jbarnette avatar

Stargazers

Boombastic avatar

Watchers

Boombastic avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.