Skip to content

Instantly share code, notes, and snippets.

@luckyruby
Last active August 29, 2015 14:03
Show Gist options
  • Save luckyruby/15d592206ac92802af4a to your computer and use it in GitHub Desktop.
Save luckyruby/15d592206ac92802af4a to your computer and use it in GitHub Desktop.
class Hand
require_relative 'deck'
def initialize
end
def new
end
def deal
deck = Deck.new
hand = deck.deal 2
flop = deck.deal 3
turn = deck.deal 1
river = deck.deal 1
@full_hand = hand + flop + turn + river
puts "HOLE CARDS: #{display(hand)}."
puts "FLOP: #{display(flop)}."
puts "TURN: #{display(turn)}."
puts "RIVER: #{display(river)}."
puts "FULL HAND: #{display(@full_hand)}"
puts flush?
end
private
def flush?
suits = @full_hand.map{|card| card[:suit]}
counts = suits.each_with_object(Hash.new(0)) {|suit, counts| counts[suit] += 1}
flush = counts.select {|k,v| v >= 5}
extract_flush(flush.keys.first) if flush.length > 0
end
def extract_flush(winning_suit)
hand = @full_hand.select {|card| card[:suit] == winning_suit}.sort_by {|card| card[:rank]}[-5..-1]
puts "You hit a flush!"
puts display(hand)
end
def display(hand)
hand.map {|card| card[:display]}.join(" ")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment