Files
game-scoring-scripts/rank.rb
T
2008-08-28 21:44:07 -07:00

65 lines
1.4 KiB
Ruby
Executable File

#!/usr/bin/env ruby
require 'hand'
require 'combinations'
def score(hand_string, verbose=false)
# split into an array of two character strings (each representing a card)
cards = hand_string.scan(/../)
# a place to store all of our scores
best_hands = nil
best_score = -1
# create and score all permutations of two 5 card hands
cards.combinations(5).each do |c|
# create each hand from two 10 character strings
hand_a = Hand.new(c.join)
hand_b = Hand.new((cards-c).join)
score = hand_a.score + hand_b.score
# save the hand if it's the best
best_hands,best_score = [hand_a,hand_b],score if score > best_score
end
# now create and score the 10 card hand
ten_card_hand = Hand.new(cards.join)
best_hands,best_score = [ten_card_hand],ten_card_hand.score if ten_card_hand.score > best_score
# DEBUG
if verbose then
best_hands.each do |h|
puts "#{h.score} points for a #{h.score_name}"
puts h
puts
end
puts "#{best_score} TOTAL POINTS"
end
# return score
best_score
end
score('tsjsqsksastcjcqckcac',true)
puts
puts
score('3d8c6s7d8h9s9dkdqd5d',true)
puts
puts
score('2s3s4s5s6s7s8s9stsjs',true)
puts
puts
score('2c3s4c5d6h7s8d9sthjs',true)
puts
puts
score('as3s4s5s6s7s8s9stsjs',true)
puts
puts
score('asadacah6s7s8s9stsjs',true)
puts
puts
score('asadackskd7s8s9stsjs',true)
puts
puts