Skip to content

Instantly share code, notes, and snippets.

@c2h2
Created May 14, 2012 19:09
Show Gist options
  • Save c2h2/2695787 to your computer and use it in GitHub Desktop.
Save c2h2/2695787 to your computer and use it in GitHub Desktop.
simulate a poker table happening chance.
require 'ruby-poker'
TOTAL_TIMES = 1000000
FACES = "AKQJT98765432"
SUITS = "CDSH"
srand
# build a deck.
deck = []
FACES.each_byte do |f|
SUITS.each_byte do |s|
deck.push(f.chr + s.chr)
end
end
#deal one hand.
def run_a_game deck
#3.times{|i| deck.shuffle!}
deck.shuffle!
raw_hand = deck[0..4]
hand = PokerHand.new(raw_hand)
hand.rank
end
a={
"Highest Card"=>0,
"Pair"=>0,
"Two pair"=>0,
"Three of a kind"=>0,
"Straight"=>0,
"Flush"=>0,
"Full house"=>0,
"Four of a kind"=>0,
"Straight Flush"=>0,
"Royal Flush"=>0
}
TOTAL_TIMES.times do |i|
res = run_a_game deck
a[res]+=1
if i%10000 == 0
puts "### #{i} times has runned. ###"
a.each_pair do |k,v|
puts "#{k}, #{v}, #{v*100.0/i.to_f}%"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment