Create a gist now

Instantly share code, notes, and snippets.

card_names = ['ace', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten',
'jack', 'queen', 'king']
card_names = [*(card_names.map { |e| "#{e} of hearts" }),
*(card_names.map { |e| "#{e} of diamonds" }),
*(card_names.map { |e| "#{e} of spades" }),
*(card_names.map { |e| "#{e} of clubs" })]
card_values = [*(1..13)] * 4
random = 52
count = 0
computer_score = 0
player_score = 0
number_of_ties = 0
while count != 26
player_card = rand(random)
puts "Your card is a #{card_names[player_card]}."
puts "Its value is #{card_values[player_card]}."
puts
player_value = card_values[player_card]
card_values.delete_at(player_card)
card_names.delete_at(player_card)
random = random - 1
computer_card = rand(random)
puts "The computer's card is a #{card_names[computer_card]}."
puts "Its value is #{card_values[computer_card]}."
computer_value = card_values[computer_card]
card_values.delete_at(computer_card)
card_names.delete_at(computer_card)
random = random - 1
if computer_value < player_value
puts 'You win this round!'
player_score = player_score + 1
elsif computer_value > player_value
puts 'You lose this round.'
computer_score = computer_score + 1
elsif computer_value == player_value
puts 'This round ends in a tie.'
number_of_ties = number_of_ties + 1
end
count = count + 1
end
puts "You won #{player_score} rounds."
puts "The computer won #{computer_score} rounds."
puts "There were #{number_of_ties} ties."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment