Skip to content

Instantly share code, notes, and snippets.

@MelanieS
Created December 7, 2010 05:41
Show Gist options
  • Save MelanieS/731512 to your computer and use it in GitHub Desktop.
Save MelanieS/731512 to your computer and use it in GitHub Desktop.
computer_dice = []
player_dice = []
count = 0
die_count = 0
match_count = 0
computer_matches = []
player_matches = []
while count < 5
throw = rand(6)
throw = throw + 1
computer_dice << throw
count = count + 1
end
new_array = []
while count > 0
throw = rand(6)
throw = throw + 1
player_dice << throw
count = count - 1
end
while die_count < 6
die_count = die_count + 1
computer_dice.each do |i|
if i == die_count
match_count = match_count + 1
end
end
computer_matches << match_count
match_count = 0
end
die_count = 0
while die_count < 6
die_count = die_count + 1
player_dice.each do |i|
if i == die_count
match_count = match_count + 1
end
end
player_matches << match_count
match_count = 0
end
player_matches = player_matches.sort
computer_matches = computer_matches.sort
puts "You rolled #{player_dice}"
puts "The computer rolled #{computer_dice}"
player_speak = 'You have '
computer_speak = 'The computer has '
def make_hand(match, speak)
if match[5] == 3 && match[4] == 2
puts "#{speak}a full house!"
return 7
elsif match[5] == 2 && match[4] == 2
puts "#{speak}two pair!"
return 6
elsif match[5] == 5
puts "#{speak}a five of a kind!"
return 5
elsif match[5] == 4
puts "#{speak}a four of a kind!"
return 4
elsif match[5] == 3
puts "#{speak}a three of a kind!"
return 3
elsif match[5] == 2
puts "#{speak}a pair!'"
return 2
else
puts "#{speak}nuthin."
return 0
end
end
player_hand = make_hand(player_matches, player_speak)
computer_hand = make_hand(computer_matches, computer_speak)
if player_hand > computer_hand
puts 'Congrats, you win!'
elsif player_hand == computer_hand
puts 'You and the computer are tied!'
elsif player_hand < computer_hand
puts 'The computer wins.'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment