Skip to content

Instantly share code, notes, and snippets.

@keppy
Created May 30, 2012 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save keppy/2835207 to your computer and use it in GitHub Desktop.
Save keppy/2835207 to your computer and use it in GitHub Desktop.
class PokerGame
include Enumerable
include Comparable
attr_reader :hand
def initialize(hands, cards)
ranks = %w{ 2 3 4 5 6 7 8 9 T J Q K A }
suits = %w{ S H D C }
card_stack = Array.new
num_hands = Array.new
suits.each {|suit|
ranks.size.times {|i|
card_stack << (ranks[i]+suit)
}
}
card_stack.shuffle!
hands.times { |y| num_hands << [] }
num_hands.each{ |hand| card_stack.collect{|card| hand << card }}
puts num_hands
end
end
PokerGame.new(2, 5)
# Currently num_hands contains all 52 cards as separate elements. I tried this
# before:
#
# hands.times do |x| (cards * x).upto(cards*(x+1)) { |z| h << card_stack[z]}
#
# which was also wrong. I'm trying to return an array containing as many arrays as
# there are hands, and inside those nested arrays should be card elements taken from
# the card_stack. The number of cards in each nested array (hand) is determined by
# the cards parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment