now generates html!

This commit is contained in:
swaits committed 2008-08-29 00:05:53 -07:00
1 parent 33da302968
commit 701d78a818
59 files changed
+355 -238

No files matched your search

+71 -65
View File
@@ -1,65 +1,71 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
class Card class Card
attr_reader :rank, :suit attr_reader :rank, :suit
def initialize(str) def initialize(str)
r = str[0,1].downcase r = str[0,1].downcase
s = str[1,1].downcase s = str[1,1].downcase
@suit = case s @suit = case s
when 's' then :spades when 's' then :spades
when 'h' then :hearts when 'h' then :hearts
when 'd' then :diamonds when 'd' then :diamonds
when 'c' then :clubs when 'c' then :clubs
end end
@rank = case r @rank = case r
when '2'..'9' then r.to_i when '2'..'9' then r.to_i
when 't' then 10 when 't' then 10
when 'j' then 11 when 'j' then 11
when 'q' then 12 when 'q' then 12
when 'k' then 13 when 'k' then 13
when 'a' then 14 when 'a' then 14
end end
end end
def rank_s def rank_long_s
case @rank ['2','3','4','5','6','7','8','9','10','Jack','Queen','King','Ace'][@rank-2]
when 2..10 then @rank.to_s end
when 11 then "Jack"
when 12 then "Queen" def suit_long_s
when 13 then "King" @suit.to_s.capitalize
when 14 then "Ace" end
end
end def rank_s
['2','3','4','5','6','7','8','9','t','j','q','k','a'][@rank-2]
def suit_s end
@suit.to_s.capitalize
end def suit_s
{:spades => 's', :hearts => 'h', :diamonds => 'd', :clubs => 'c'}[@suit]
def to_s end
rank_s + "-" + suit_s
end def to_s
rank_s + suit_s
def ==(other) end
@rank == other.rank && @suit == other.suit
end def to_long_s
rank_long_s + '-' + suit_long_s
def <=>(other) end
if @rank != other.rank
@rank <=> other.rank def ==(other)
else @rank == other.rank && @suit == other.suit
# order is Spades, Hearts, Diamonds, Clubs (conveniently reverse alphabetical) end
other.suit_s <=> suit_s
end def <=>(other)
end if @rank != other.rank
@rank <=> other.rank
def eql?(other) else
self == other # order is Spades, Hearts, Diamonds, Clubs (conveniently reverse alphabetical)
end other.suit_s <=> suit_s
end
def hash end
to_s.hash
end def eql?(other)
end self == other
end
def hash
to_s.hash
end
end
+16 -16
View File
@@ -1,16 +1,16 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
class Array class Array
def combinations n def combinations n
result = Array.new result = Array.new
if n > 0 if n > 0
(0 .. self.length - n).each do |i| (0 .. self.length - n).each do |i|
combs = self[i + 1 .. -1].combinations(n - 1) combs = self[i + 1 .. -1].combinations(n - 1)
combs = [[]] if combs.empty? combs = [[]] if combs.empty?
combs.collect {|comb| [self[i]] + comb}.each {|x| result << x} combs.collect {|comb| [self[i]] + comb}.each {|x| result << x}
end end
end end
return result return result
end end
end end
+29
View File
@@ -0,0 +1,29 @@
/*
* Tripoli is a generic CSS standard for HTML rendering.
* Copyright (C) 2007-2008 David Hellsing
*
* http://devkick.com/lab/tripoli/
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**
_______________________________
RESET */
*{text-decoration:none;font-size:1em;outline:none;margin:0;padding:0}code,kbd,samp,pre,tt,var,textarea,input,select,isindex,listing,xmp,plaintext{font:inherit;white-space:normal}a,img,a img,iframe,form,abbr,acronym,object,applet,table,a abbr,a acronym{border-width:0}dfn,i,cite,var,address,em{font-style:normal}th,b,strong,h1,h2,h3,h4,h5,h6,dt{font-weight:400}caption,th,td{text-align:left}html{background:#FFF;color:#000;line-height:1;font-family:arial, sans-serif}/* \*/html{font-family:sans-serif}/* */q{quotes:"\201C""\201D""\2018""\2019"}ul,ol,dir,menu{list-style:none}sub,sup{vertical-align:baseline}a{color:inherit}/*
_______________________________
DISABLE DEPRECATED HTML */
font,basefont{color:inherit;font:inherit;font-size:100%}center,*[align]{text-align:inherit}s,strike,u{text-decoration:inherit}img{border:none;margin:0}ol{list-style-type:decimal}body{background-color:transparent}tr,th,td{width:auto;height:auto;background-color:transparent;vertical-align:inherit;border:none}table[border],.content table[border]{border-collapse:separate;border-spacing:0}nobr{white-space:normal}marquee{overflow:visible;-moz-binding:none}blink{text-decoration:none}/*
_______________________________
GENERAL */
html{font-size:125%}body{font-size:50%}a{text-decoration:underline}strong,th,thead td,h1,h2,h3,h4,h5,h6,dt{font-weight:700}cite,em,dfn{font-style:italic}code,kbd,samp,pre,tt,var,input[type='text'],input[type='password'],textarea{font-size:100%;font-family:mono-space,monospace}pre{white-space:pre}pre *{font-size:100%;white-space:pre}del{text-decoration:line-through}ins,dfn{border-bottom:1px solid #000}small,sup,sub{font-size:85%}big{font-size:125%;line-height:80%}abbr,acronym{text-transform:uppercase;font-size:85%;letter-spacing:.1em}abbr[title],acronym[title],dfn[title]{cursor:help;border-bottom:1px dotted #000}sup{vertical-align:super}sub{vertical-align:sub}blockquote{padding-left:2.2em}hr{display:none/* We will re-reset it later for content */}:lang(af),:lang(nl),:lang(pl){quotes:'\201E' '\201D' '\201A' '\2019'}:lang(bg),:lang(cs),:lang(de),:lang(is),:lang(lt),:lang(sk),:lang(sr),:lang(ro){quotes:'\201E' '\201C' '\201A' '\2018'}:lang(da),:lang(hr){quotes:'\00BB' '\00AB' '\203A' '\2039'}:lang(el),:lang(es),:lang(sq),:lang(tr){quotes:'\00AB' '\00BB' '\2039' '\203A'}:lang(en-GB){quotes:'\2018' '\2019' '\201C' '\201D'}:lang(fi),:lang(sv){quotes:'\201D' '\201D' '\2019' '\2019'}:lang(fr){quotes:'\ab\2005' '\2005\bb' '\2039\2005' '\2005\203a'}*[lang|='en'] q:before{content:'\201C'}*[lang|='en'] q:after{content:'\201D'}*[lang|='en'] q q:before{content:'\2018'}*[lang|='en'] q q:after{content:'\2019'}input,select,button{cursor:pointer}input[type='text'],input[type='password']{cursor:text}input[type='hidden']{display:none}/*
_______________________________
CONTENT */
.content{font-size:1.2em;line-height:1.6em}.content h1{font-size:1.6em;line-height:1;margin:1em 0 .5em}.content h2{font-size:1.5em;line-height:1;margin:1.07em 0 .535em}.content h3{font-size:1.4em;line-height:1;margin:1.14em 0 .57em}.content h4{font-size:1.3em;line-height:1;margin:1.23em 0 .615em}.content h5{font-size:1.2em;line-height:1;margin:1.33em 0 .67em}.content h6{font-size:1em;line-height:1;margin:1.6em 0 .8em}.content hr{display:block;background:#000;color:#000;width:100%;height:1px;border:none}.content ul{list-style:disc outside}.content ol{list-style:decimal outside}.content table{border-collapse:collapse}.content hr,.content p,.content ul,.content ol,.content dl,.content pre,.content address,.content table,.content form{margin-bottom:1.6em}.content p+p{margin-top:-.8em}.content fieldset{margin:1.6em 0;padding:1.6em}/* \*/.content legend{padding-left:.8em;padding-right:.8em}/* *//* for Opera 8 */@media all and min-width 0px{.content legend{margin-bottom:1.6em}.content fieldset{margin-top:0}.content[class^='content'] fieldset{margin-top:1.6em}}.content fieldset>*:first-child{margin-top:0}.content textarea,.content input[type='text']{padding:.1em .2em}.content input{padding:.2em .1em}.content select{padding:.2em .1em 0}.content select[multiple]{margin-bottom:.8em}.content option{padding:0 .4em .1em}.content button{padding:.3em .5em}.content input[type='radio']{position:relative;bottom:-.2em}.content dt{margin-top:.8em;margin-bottom:.4em}.content ul,.content ol{margin-left:2.2em}.content caption,.content form div{padding-bottom:.8em}.content ul ul,content ol ul,.content ul ol,content ol ol{margin-bottom:0}/*
_______________________________
VISUAL PLUG */
blockquote{color:#666}blockquote > *:first-child:before /* Tripoli bonus: pure CSS blockquote */{content:"\201C";font-size:2.5em;margin-left:-.62em;font-family:georgia,serif;padding-right:.2em;color:#aaa;line-height:0}abbr[title],acronym[title],dfn[title]{border-bottom:1px solid #ccc}ins,dfn{border-bottom-color:#666}del{color:#666}fieldset{border-color:#ccc}textarea,input[type='text'],input[type='password'],select{border:1px solid #ccc;background:#fff}fieldset{border:1px solid #ccc}textarea:hover,input[type='text']:hover,input[type='password']:hover,select:hover{border-color:#aaa}textarea:focus,input[type='text']:focus,input[type='password']:focus,select:focus{outline:2px solid #e4e4e4;border-color:#888}.content hr{background:#aaa;color:#aaa}.content table{border-top:1px solid #ccc;border-left:1px solid #ccc}.content th,.content td{border-bottom:1px solid #ddd;border-right:1px solid #ccc}.content th,.content td{padding:.8em}a:link{color:#36c}a:visited{color:#99c}a:hover,code,pre{color:#c33}a:active,.a:focus{color:#000}/*
_______________________________
TYPE PLUG */
.alt{font-family:"baskerville italic","Warnock Pro","Goudy Old Style","Palatino","palatino linotype","Book Antiqua",Georgia, serif;font-style:italic;font-weight:400}.dquo{margin-left:-.55em}/*
_______________________________
END */
+14
View File
@@ -0,0 +1,14 @@
/*
* Tripoli is a generic CSS standard for HTML rendering.
* Copyright (C) 2007-2008 David Hellsing
*
* http://devkick.com/lab/tripoli/
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
**
_______________________________
BASE.IE */
textarea{white-space:pre}.content legend{margin-bottom:1.6em}.content fieldset{padding-top:0}sup,sub{font-size:100%}.content legend:first-child{margin-top:0}a abbr,a acronym{text-decoration:underline}* html .content blockquote *{margin:.8em 0}* html input{cursor:expression(this.type=='text' || this.type=='password' ? 'text' : 'pointer');display:expression(this.type=='hidden' ? 'none' : 'inline')}* html .content textarea,* html .content input,.content input[type='submit'],.content input[type='button']{padding:0}/*
_______________________________
END */
+93 -93
View File
@@ -1,93 +1,93 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'card' require 'card'
class Hand class Hand
def initialize(hand_string) def initialize(hand_string)
@cards = hand_string.scan(/../).collect { |s| Card.new(s) }.sort @cards = hand_string.scan(/../).collect { |s| Card.new(s) }.sort
end end
def legal? def legal?
@cards.size == @cards.sort.uniq.size && [5,10].include?(@cards.size) @cards.size == @cards.sort.uniq.size && [5,10].include?(@cards.size)
end end
def illegal? def illegal?
!(legal?) !(legal?)
end end
def rank def rank
return nil if illegal? return nil if illegal?
# array of suits, ranks # array of suits, ranks
suits = @cards.collect { |c| c.suit_s } suits = @cards.collect { |c| c.suit_s }
ranks = @cards.collect { |c| c.rank } ranks = @cards.collect { |c| c.rank }
# count of suits # count of suits
suit_counts = Hash.new(0) suit_counts = Hash.new(0)
suits.each { |s| suit_counts[s] += 1 } suits.each { |s| suit_counts[s] += 1 }
# count of ranks # count of ranks
rank_counts = Hash.new(0) rank_counts = Hash.new(0)
ranks.each { |s| rank_counts[s] += 1 } ranks.each { |s| rank_counts[s] += 1 }
# test for straight & flush # test for straight & flush
straight = (ranks.sort == (ranks.min .. ranks.max).to_a) straight = (ranks.sort == (ranks.min .. ranks.max).to_a)
flush = (suits.sort.uniq.size == 1) flush = (suits.sort.uniq.size == 1)
# rank hand # rank hand
return :royal_flush if straight && flush && ranks.min == 10 return :royal_flush if straight && flush && ranks.min == 10
return :straight_flush if straight && flush return :straight_flush if straight && flush
return :four_of_a_kind if [1,4] == rank_counts.values.sort return :four_of_a_kind if [1,4] == rank_counts.values.sort
return :full_house if [2,3] == rank_counts.values.sort return :full_house if [2,3] == rank_counts.values.sort
return :flush if flush return :flush if flush
return :straight if straight return :straight if straight
# nothing # nothing
nil nil
end end
def score def score
r = rank r = rank
return 0 if r.nil? return 0 if r.nil?
# ten card hands # ten card hands
return 80 if @cards.size == 10 && r == :straight_flush return 80 if @cards.size == 10 && r == :straight_flush
return 40 if @cards.size == 10 && r == :flush return 40 if @cards.size == 10 && r == :flush
return 20 if @cards.size == 10 && r == :straight return 20 if @cards.size == 10 && r == :straight
# five card hands # five card hands
return 21 if r == :royal_flush return 21 if r == :royal_flush
return 20 if r == :straight_flush return 20 if r == :straight_flush
return 15 if r == :four_of_a_kind return 15 if r == :four_of_a_kind
return 10 if r == :full_house return 10 if r == :full_house
return 7 if r == :flush return 7 if r == :flush
return 5 if r == :straight return 5 if r == :straight
# nothing # nothing
return 0 return 0
end end
def score_name def score_name
rank.to_s.gsub(/_/,' ') if rank rank.to_s.gsub(/_/,' ') if rank
end end
def to_s def to_s
@cards.collect { |c| c.to_s }.join(', ') @cards.collect { |c| c.to_s }.join(', ')
end end
def hash def hash
to_s.hash to_s.hash
end end
def <=>(other) def <=>(other)
to_s <=> other.to_s to_s <=> other.to_s
end end
end end
+9
View File
@@ -0,0 +1,9 @@
tj,tsjsqsksastcjcqckcac
tj,tsjsqsksastcjcqckcac
cathy,tsjsqsksastcjcqckcac
cathy,3d8c6s7d8h9s9dkdqd5d
cathy,2s3s4s5s6s7s8s9stsjs
eileen,2c3s4c5d6h7s8d9sthjs
randy,as3s4s5s6s7s8s9stsjs
jen,asadacah6s7s8s9stsjs
jen,asadackskd7s8s9stsjs
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 650 B

After

Width:  |  Height:  |  Size: 465 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 B

After

Width:  |  Height:  |  Size: 443 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 654 B

After

Width:  |  Height:  |  Size: 474 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 557 B

After

Width:  |  Height:  |  Size: 384 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 689 B

After

Width:  |  Height:  |  Size: 482 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 645 B

After

Width:  |  Height:  |  Size: 476 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 697 B

After

Width:  |  Height:  |  Size: 492 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 595 B

After

Width:  |  Height:  |  Size: 468 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 753 B

After

Width:  |  Height:  |  Size: 515 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 676 B

After

Width:  |  Height:  |  Size: 503 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 714 B

After

Width:  |  Height:  |  Size: 533 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 631 B

After

Width:  |  Height:  |  Size: 504 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 812 B

After

Width:  |  Height:  |  Size: 546 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 702 B

After

Width:  |  Height:  |  Size: 524 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 807 B

After

Width:  |  Height:  |  Size: 549 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 678 B

After

Width:  |  Height:  |  Size: 516 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 790 B

After

Width:  |  Height:  |  Size: 573 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 738 B

After

Width:  |  Height:  |  Size: 552 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 812 B

After

Width:  |  Height:  |  Size: 579 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 716 B

After

Width:  |  Height:  |  Size: 541 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 775 B

After

Width:  |  Height:  |  Size: 590 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 552 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 841 B

After

Width:  |  Height:  |  Size: 609 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 719 B

After

Width:  |  Height:  |  Size: 573 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 877 B

After

Width:  |  Height:  |  Size: 619 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 815 B

After

Width:  |  Height:  |  Size: 571 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 893 B

After

Width:  |  Height:  |  Size: 648 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 810 B

After

Width:  |  Height:  |  Size: 590 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 971 B

After

Width:  |  Height:  |  Size: 647 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 812 B

After

Width:  |  Height:  |  Size: 593 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 940 B

After

Width:  |  Height:  |  Size: 664 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 831 B

After

Width:  |  Height:  |  Size: 621 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 521 B

After

Width:  |  Height:  |  Size: 440 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 570 B

After

Width:  |  Height:  |  Size: 436 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 581 B

After

Width:  |  Height:  |  Size: 443 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 691 B

After

Width:  |  Height:  |  Size: 497 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 912 B

After

Width:  |  Height:  |  Size: 666 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 841 B

After

Width:  |  Height:  |  Size: 629 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 977 B

After

Width:  |  Height:  |  Size: 699 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 863 B

After

Width:  |  Height:  |  Size: 650 B

+123 -64
View File
@@ -1,64 +1,123 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'hand' require 'hand'
require 'combinations' require 'combinations'
def score(hand_string, verbose=false) def score(hand_string, verbose=false)
# split into an array of two character strings (each representing a card) # split into an array of two character strings (each representing a card)
cards = hand_string.scan(/../) cards = hand_string.scan(/../)
# a place to store all of our scores # a place to store all of our scores
best_hands = nil best_hands = nil
best_score = -1 best_score = -1
# create and score all permutations of two 5 card hands # create and score all permutations of two 5 card hands
cards.combinations(5).each do |c| cards.combinations(5).each do |c|
# create each hand from two 10 character strings # create each hand from two 10 character strings
hand_a = Hand.new(c.join) hand_a = Hand.new(c.join)
hand_b = Hand.new((cards-c).join) hand_b = Hand.new((cards-c).join)
score = hand_a.score + hand_b.score score = hand_a.score + hand_b.score
# save the hand if it's the best # save the hand if it's the best
best_hands,best_score = [hand_a,hand_b],score if score > best_score best_hands,best_score = [hand_a,hand_b],score if score > best_score
end end
# now create and score the 10 card hand # now create and score the 10 card hand
ten_card_hand = Hand.new(cards.join) 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 best_hands,best_score = [ten_card_hand],ten_card_hand.score if ten_card_hand.score > best_score
# DEBUG # DEBUG
if verbose then if verbose then
best_hands.each do |h| best_hands.each do |h|
puts "#{h.score} points for a #{h.score_name}" puts "#{h.score} points for a #{h.score_name}"
puts h puts h
puts puts
end end
puts "#{best_score} TOTAL POINTS" puts "#{best_score} TOTAL POINTS"
end end
# return score # return score
best_score [best_score, best_hands]
end end
score('tsjsqsksastcjcqckcac',true) PlayerNames = {
puts 'aaron' => 'Aaron Dickinson',
puts 'adam' => 'Adam Dickinson',
score('3d8c6s7d8h9s9dkdqd5d',true) 'angel' => 'Angel Madigan',
puts 'cathy' => 'Cathy Waits',
puts 'dundee' => 'Dundee Reyno',
score('2s3s4s5s6s7s8s9stsjs',true) 'eddy' => 'Eddy Cramm',
puts 'eileen' => 'Eileen Gher',
puts 'eryn' => 'Eryn Roston',
score('2c3s4c5d6h7s8d9sthjs',true) 'francois' => 'François Bertrand',
puts 'fred' => 'Fred Thompson',
puts 'george' => 'George Rothrock',
score('as3s4s5s6s7s8s9stsjs',true) 'jeff' => 'Jeff Curley',
puts 'jen' => 'Jen Gratz',
puts 'john' => 'John Yuill',
score('asadacah6s7s8s9stsjs',true) 'jonathan' => 'Jonathan Leghart',
puts 'josh' => 'Josh Hart',
puts 'lonna' => 'Lonna Leghart',
score('asadackskd7s8s9stsjs',true) 'mike' => 'Mike Skinner',
puts 'peter' => 'Peter Heino',
puts '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('hands.txt').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>'