Created
May 30, 2012 09:48
-
-
Save keppy/2835207 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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