#!/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, best_hands] end PlayerNames = { 'aaron' => 'Aaron Dickinson', 'adam' => 'Adam Dickinson', 'angel' => 'Angel Madigan', 'cathy' => 'Cathy Waits', 'dundee' => 'Dundee Reyno', 'eddy' => 'Eddy Cramm', 'eileen' => 'Eileen Gher', 'eryn' => 'Eryn Roston', 'francois' => 'François Bertrand', 'fred' => 'Fred Thompson', 'george' => 'George Rothrock', 'jeff' => 'Jeff Curley', 'jen' => 'Jen Gratz', 'john' => 'John Yuill', 'jonathan' => 'Jonathan Leghart', 'josh' => 'Josh Hart', 'lonna' => 'Lonna Leghart', 'mike' => 'Mike Skinner', 'peter' => 'Peter Heino', 'ramana' => 'Ramana Prakash', 'randy' => 'Randy Yumul', 'rob' => 'Rob Whyte', 'ryan' => 'Ryan Mack', 'shaelagh' => 'Shaelagh Skinner', 'stephanie' => 'Stéphanie Plante', 'steven' => 'Steven Gher', 'swaits' => 'Stephen Waits', 'tim' => 'Tim Flier', 'tj' => 'TJ Madigan', } total = Hash.new(0) puts '' puts 'Super Babel Scoring' puts '' puts '' puts ' ' puts '' puts '
' puts '

Hand Log

' puts "" puts "" even = false IO.readlines(ARGV[0]).each do |line| player,cards = line.chomp.split(/,/) score,hands = score(cards) total[player.downcase] += score evenorodd = even ? "even" : "odd" even = !even puts "" puts " " colspan = 3 - hands.size hands.each do |h| puts " " end puts " " puts " " puts "" end puts "
PlayerHandsScoreTotal
#{PlayerNames[player]} [#{player}]" h.to_s.gsub(/ /,'').split(',').each { |card| puts "" } puts "
#{h.score_name} (#{h.score})
#{score}#{total[player]}
" puts '

Total Scores

' total.sort { |a,b| a[1] <=> b[1] }.reverse.each { |s| puts "#{PlayerNames[s[0]]} [#{s[0]}] - #{s[1]}
" } puts '
' puts '' puts ''