Files
game-scoring-scripts/rank.rb
T

124 lines
3.3 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, 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 '<html><head>'
puts '<title>Super Babel Scoring</title>'
puts '<link href="css/tripoli.simple.css" type="text/css" rel="stylesheet">'
puts '<!--[if IE]><link rel="stylesheet" type="text/css" href="css/tripoli.simple.ie.css"><![endif]-->'
puts ' <style type="text/css">
tr.even td {
background-color: #f6f6f6;
}
tr.odd td {
background-color: #ffffff;
}
</style>'
puts '</head><body>'
puts '<div class="content" style="text-align:left;margin:20px auto;padding:20px">'
puts '<h1>Hand Log</h1>'
puts "<table>"
puts "<tr><th>Player</th><th colspan=2>Hands</th><th>Score</th><th>Total</th></tr>"
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 "<tr class=\"#{evenorodd}\">"
puts " <td>#{PlayerNames[player]} [#{player}]</td>"
colspan = 3 - hands.size
hands.each do |h|
puts " <td colspan=\"#{colspan}\">"
h.to_s.gsub(/ /,'').split(',').each { |card| puts "<img src=\"img/#{card}.gif\">" }
puts "<br/>#{h.score_name} (#{h.score})</td>"
end
puts " <td>#{score}</td>"
puts " <td>#{total[player]}</td>"
puts "</tr>"
end
puts "</table>"
puts '<h1>Total Scores</h1>'
total.sort { |a,b| a[1] <=> b[1] }.reverse.each { |s| puts "#{PlayerNames[s[0]]} [#{s[0]}] - #{s[1]}<br/>" }
puts '</div>'
puts '</body>'
puts '</html>'