From 177cf15180463e50ac47a21ffa2ce643b9239f13 Mon Sep 17 00:00:00 2001 From: Jonas Schubert Erlandsson Date: Mon, 24 Aug 2015 19:23:40 +0200 Subject: [PATCH 1/9] Changes README format form rdoc to markdown. --- README.rdoc => README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) rename README.rdoc => README.md (93%) diff --git a/README.rdoc b/README.md similarity index 93% rename from README.rdoc rename to README.md index ceac9e6..b9fdab6 100644 --- a/README.rdoc +++ b/README.md @@ -1,12 +1,12 @@ -= Poker library in Ruby +# Poker library in Ruby === Author:: {Andrew C. Greenberg}[http://lawhacker.com] -Email:: [andrewcgreenberg] [at] gmail.com +Email:: andrewcgreenberg [at] gmail.com GitHub:: http://github.com/wizarderdna/ruby-poker Forked from {Rob Olson's}[http://thinkingdigitally.com] excellent first cut at a ruby-native evaluator. -== Description +## Description Ruby-Poker handles the logic for getting the rank of a poker hand. It can also be used to compare two or more hands to determine which hand has the highest poker value. @@ -30,17 +30,17 @@ CactusKev2p2Evaluator - Carrying lookup tables to the limit, this evaluator is b CactusKevBinarySearchEvaluator 26.210000 0.090000 26.300000 ( 26.298261) HurleyEvaluator 88.100000 1.260000 89.360000 ( 89.362515) -== Install +## Install - sudo gem install ruby-poker + gem install ruby-poker -== Example +## Example require 'rubygems' require 'ruby-poker' hand1 = PokerHand.new("8H 9C TC JD QH") # uses the hurley evaluator by default - require 'ruby-poker/cactus_kev_2p2_evaluator' # loads the monstrously large table for 2p2 + require 'ruby-poker/cactus_kev_2p2_evaluator' # loads the monstrously large table for 2p2 hand2 = PokerHand.new(["3D", "3C", "3S", "KD", "AH"], CactusKev2p2Evaluator) # uses the super-fast two plus two evaluator puts hand1 => 8h 9c Tc Jd Qh (Straight) puts hand1.just_cards => 8h 9c Tc Jd Qh @@ -49,7 +49,7 @@ CactusKev2p2Evaluator - Carrying lookup tables to the limit, this evaluator is b puts hand2.rank => Three of a kind puts hand1 > hand2 => true -== Duplicates +## Duplicates By default ruby-poker will not raise an exception if you add the same card to a hand twice. You can tell ruby-poker to not allow duplicates by doing the following @@ -57,14 +57,14 @@ By default ruby-poker will not raise an exception if you add the same card to a Place that line near the beginning of your program. The change is program wide so once allow_duplicates is set to false, _all_ poker hands will raise an exception if a duplicate card is added to the hand. -== Compatibility +## Compatibility Ruby-Poker is compatible with Ruby 1.8.6 and Ruby 1.9.1. -== History +## History In the 0.2.0 release Patrick Hurley's Texas Holdem code from http://www.rubyquiz.com/quiz24.html was merged into ruby-poker. -== License +## License This is free software; you can redistribute it and/or modify it under the terms of the BSD license. See LICENSE for more details. \ No newline at end of file From 9682368f3a122068609b99ff7c482959faa8b2cb Mon Sep 17 00:00:00 2001 From: Jonas Schubert Erlandsson Date: Mon, 24 Aug 2015 19:35:15 +0200 Subject: [PATCH 2/9] Fixes header formatting. Adds markdown links to all links. Adds some inline code markup for inline code. --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b9fdab6..b97a824 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Poker library in Ruby -=== -Author:: {Andrew C. Greenberg}[http://lawhacker.com] -Email:: andrewcgreenberg [at] gmail.com -GitHub:: http://github.com/wizarderdna/ruby-poker -Forked from {Rob Olson's}[http://thinkingdigitally.com] excellent first cut at a ruby-native evaluator. +Author: [Andrew C. Greenberg](http://lawhacker.com) +Email: andrewcgreenberg [at] gmail.com +GitHub: [https://github.com/wizarderdna/ruby-poker](https://github.com/wizarderdna/ruby-poker) + +Forked from [Rob Olson's](http://thinkingdigitally.com) excellent first cut at a ruby-native evaluator. ## Description @@ -55,7 +55,7 @@ By default ruby-poker will not raise an exception if you add the same card to a PokerHand.allow_duplicates = false -Place that line near the beginning of your program. The change is program wide so once allow_duplicates is set to false, _all_ poker hands will raise an exception if a duplicate card is added to the hand. +Place that line near the beginning of your program. The change is program wide so once `allow_duplicates` is set to `false`, _all_ poker hands will raise an exception if a duplicate card is added to the hand. ## Compatibility @@ -63,8 +63,8 @@ Ruby-Poker is compatible with Ruby 1.8.6 and Ruby 1.9.1. ## History -In the 0.2.0 release Patrick Hurley's Texas Holdem code from http://www.rubyquiz.com/quiz24.html was merged into ruby-poker. +In the 0.2.0 release Patrick Hurley's Texas Holdem code from [http://www.rubyquiz.com/quiz24.html](http://www.rubyquiz.com/quiz24.html) was merged into ruby-poker. ## License -This is free software; you can redistribute it and/or modify it under the terms of the BSD license. See LICENSE for more details. \ No newline at end of file +This is free software; you can redistribute it and/or modify it under the terms of the BSD license. See [LICENSE](LICENSE) for more details. \ No newline at end of file From cc0483a9eec80a2bf043549bf5af9ebd722e4211 Mon Sep 17 00:00:00 2001 From: Jonas Schubert Erlandsson Date: Mon, 24 Aug 2015 19:37:09 +0200 Subject: [PATCH 3/9] Adds emphasis to the different evaluators. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b97a824..d8e4a3c 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,13 @@ Card representations can be passed to the PokerHand constructor as a string or a Plural evaluators may be installed and tested for comparative accuracy and efficiency. By default, HurleyEvaluator, the Patrick Hurley algorithm (slow, but straightforward to understand and space-efficient) is used. Other evaluators include: -CactusKevBinarySearchEvaluator - The original Cactus-Kev evaluator, which exploits four smallish (about 10k FixedInt) lookup tables to quickly compute a value, but only for 5-card hands. The algorithm is extended to 6- and 7-card hands by doing evaluations of each 5-card combination. Even doing 21 times as many valuations, the Cactus-Kev evaluator is considerably faster than the Hurley algorithm for 7-card hands. +**CactusKevBinarySearchEvaluator** - The original Cactus-Kev evaluator, which exploits four smallish (about 10k FixedInt) lookup tables to quickly compute a value, but only for 5-card hands. The algorithm is extended to 6- and 7-card hands by doing evaluations of each 5-card combination. Even doing 21 times as many valuations, the Cactus-Kev evaluator is considerably faster than the Hurley algorithm for 7-card hands. -CactusKevEvaluator - The original Cactus-Kev evaluator, replacing the binary search lookup in the third table with a perfect hash. +**CactusKevEvaluator** - The original Cactus-Kev evaluator, replacing the binary search lookup in the third table with a perfect hash. -CactusKevRubyEvaluator - A ruby-based variation on the CactusKev solution, using a single table and ruby hashes. This turned out to run slightly faster than the CK evaluator. It, too, is limited to 5-card hands, using an unrolled version of the combination solution for original CK. +**CactusKevRubyEvaluator** - A ruby-based variation on the CactusKev solution, using a single table and ruby hashes. This turned out to run slightly faster than the CK evaluator. It, too, is limited to 5-card hands, using an unrolled version of the combination solution for original CK. -CactusKev2p2Evaluator - Carrying lookup tables to the limit, this evaluator is based on the two-plus-two valuation optimization thread, using a monstrously large lookup table that represents a state machine for 7-card hands. Unlike the previous tables, it does not require any special processing beyond serially looking up (a single table index for each card) the cards in the hand to produce a hand valuation score. This runs significantly faster (40x) than the Hurley evaluator: +**CactusKev2p2Evaluator** - Carrying lookup tables to the limit, this evaluator is based on the two-plus-two valuation optimization thread, using a monstrously large lookup table that represents a state machine for 7-card hands. Unlike the previous tables, it does not require any special processing beyond serially looking up (a single table index for each card) the cards in the hand to produce a hand valuation score. This runs significantly faster (40x) than the Hurley evaluator: 7-card shootout (100,000 random hands) user system total real From eac4964dddb90f18658553e5ccf95ca1c03e447f Mon Sep 17 00:00:00 2001 From: Jonas Schubert Erlandsson Date: Mon, 24 Aug 2015 19:39:29 +0200 Subject: [PATCH 4/9] Changes code blocks syntax to allow declaring language. --- README.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d8e4a3c..95ce4e1 100644 --- a/README.md +++ b/README.md @@ -36,24 +36,28 @@ Plural evaluators may be installed and tested for comparative accuracy and effic ## Example - require 'rubygems' - require 'ruby-poker' - - hand1 = PokerHand.new("8H 9C TC JD QH") # uses the hurley evaluator by default - require 'ruby-poker/cactus_kev_2p2_evaluator' # loads the monstrously large table for 2p2 - hand2 = PokerHand.new(["3D", "3C", "3S", "KD", "AH"], CactusKev2p2Evaluator) # uses the super-fast two plus two evaluator - puts hand1 => 8h 9c Tc Jd Qh (Straight) - puts hand1.just_cards => 8h 9c Tc Jd Qh - puts hand1.rank => Straight - puts hand2 => 3d 3c 3s Kd Ah (Three of a kind) - puts hand2.rank => Three of a kind - puts hand1 > hand2 => true +```ruby +require 'rubygems' +require 'ruby-poker' + +hand1 = PokerHand.new("8H 9C TC JD QH") # uses the hurley evaluator by default +require 'ruby-poker/cactus_kev_2p2_evaluator' # loads the monstrously large table for 2p2 +hand2 = PokerHand.new(["3D", "3C", "3S", "KD", "AH"], CactusKev2p2Evaluator) # uses the super-fast two plus two evaluator +puts hand1 => 8h 9c Tc Jd Qh (Straight) +puts hand1.just_cards => 8h 9c Tc Jd Qh +puts hand1.rank => Straight +puts hand2 => 3d 3c 3s Kd Ah (Three of a kind) +puts hand2.rank => Three of a kind +puts hand1 > hand2 => true +``` ## Duplicates By default ruby-poker will not raise an exception if you add the same card to a hand twice. You can tell ruby-poker to not allow duplicates by doing the following - PokerHand.allow_duplicates = false +```ruby +PokerHand.allow_duplicates = false +``` Place that line near the beginning of your program. The change is program wide so once `allow_duplicates` is set to `false`, _all_ poker hands will raise an exception if a duplicate card is added to the hand. From ae1ca6e5c8e070dd691937e38df1fc94031179ee Mon Sep 17 00:00:00 2001 From: Jonas Schubert Erlandsson Date: Mon, 24 Aug 2015 19:40:48 +0200 Subject: [PATCH 5/9] Adds comment hashes in example code to clarify what is code and what is output. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 95ce4e1..4f22e04 100644 --- a/README.md +++ b/README.md @@ -43,12 +43,12 @@ require 'ruby-poker' hand1 = PokerHand.new("8H 9C TC JD QH") # uses the hurley evaluator by default require 'ruby-poker/cactus_kev_2p2_evaluator' # loads the monstrously large table for 2p2 hand2 = PokerHand.new(["3D", "3C", "3S", "KD", "AH"], CactusKev2p2Evaluator) # uses the super-fast two plus two evaluator -puts hand1 => 8h 9c Tc Jd Qh (Straight) -puts hand1.just_cards => 8h 9c Tc Jd Qh -puts hand1.rank => Straight -puts hand2 => 3d 3c 3s Kd Ah (Three of a kind) -puts hand2.rank => Three of a kind -puts hand1 > hand2 => true +puts hand1 # => 8h 9c Tc Jd Qh (Straight) +puts hand1.just_cards # => 8h 9c Tc Jd Qh +puts hand1.rank # => Straight +puts hand2 # => 3d 3c 3s Kd Ah (Three of a kind) +puts hand2.rank # => Three of a kind +puts hand1 > hand2 # => true ``` ## Duplicates From 99d460d6eafd2aafe21f4178882b68d1bcd175d3 Mon Sep 17 00:00:00 2001 From: Jonas Schubert Erlandsson Date: Mon, 24 Aug 2015 19:44:20 +0200 Subject: [PATCH 6/9] Adds ms per hand to the stats and a newline at the end of the file. --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4f22e04..1176f7f 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,12 @@ Plural evaluators may be installed and tested for comparative accuracy and effic **CactusKev2p2Evaluator** - Carrying lookup tables to the limit, this evaluator is based on the two-plus-two valuation optimization thread, using a monstrously large lookup table that represents a state machine for 7-card hands. Unlike the previous tables, it does not require any special processing beyond serially looking up (a single table index for each card) the cards in the hand to produce a hand valuation score. This runs significantly faster (40x) than the Hurley evaluator: 7-card shootout (100,000 random hands) - user system total real - CactusKev2p2Evaluator 1.930000 0.080000 2.010000 ( 2.006648) - CactusKevEvaluator 12.280000 0.100000 12.380000 ( 12.382839) - CactusKevRubyEvaluator 14.290000 0.120000 14.410000 ( 14.404539) - CactusKevBinarySearchEvaluator 26.210000 0.090000 26.300000 ( 26.298261) - HurleyEvaluator 88.100000 1.260000 89.360000 ( 89.362515) + user system total real ms per hand + CactusKev2p2Evaluator 1.930000 0.080000 2.010000 ( 2.006648) 0.02006648 + CactusKevEvaluator 12.280000 0.100000 12.380000 ( 12.382839) 0.12382839 + CactusKevRubyEvaluator 14.290000 0.120000 14.410000 ( 14.404539) 0.14404539 + CactusKevBinarySearchEvaluator 26.210000 0.090000 26.300000 ( 26.298261) 0.26298261 + HurleyEvaluator 88.100000 1.260000 89.360000 ( 89.362515) 0.89362515 ## Install @@ -71,4 +71,4 @@ In the 0.2.0 release Patrick Hurley's Texas Holdem code from [http://www.rubyqui ## License -This is free software; you can redistribute it and/or modify it under the terms of the BSD license. See [LICENSE](LICENSE) for more details. \ No newline at end of file +This is free software; you can redistribute it and/or modify it under the terms of the BSD license. See [LICENSE](LICENSE) for more details. From c1379dcc5c7c4ac65162dc61412909c5209ae8fb Mon Sep 17 00:00:00 2001 From: Jonas Schubert Erlandsson Date: Mon, 24 Aug 2015 19:45:40 +0200 Subject: [PATCH 7/9] Removes some whitespace to make the time table fit in a Github column. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1176f7f..d7307fb 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,12 @@ Plural evaluators may be installed and tested for comparative accuracy and effic **CactusKev2p2Evaluator** - Carrying lookup tables to the limit, this evaluator is based on the two-plus-two valuation optimization thread, using a monstrously large lookup table that represents a state machine for 7-card hands. Unlike the previous tables, it does not require any special processing beyond serially looking up (a single table index for each card) the cards in the hand to produce a hand valuation score. This runs significantly faster (40x) than the Hurley evaluator: 7-card shootout (100,000 random hands) - user system total real ms per hand - CactusKev2p2Evaluator 1.930000 0.080000 2.010000 ( 2.006648) 0.02006648 - CactusKevEvaluator 12.280000 0.100000 12.380000 ( 12.382839) 0.12382839 - CactusKevRubyEvaluator 14.290000 0.120000 14.410000 ( 14.404539) 0.14404539 - CactusKevBinarySearchEvaluator 26.210000 0.090000 26.300000 ( 26.298261) 0.26298261 - HurleyEvaluator 88.100000 1.260000 89.360000 ( 89.362515) 0.89362515 + user system total real ms per hand + CactusKev2p2Evaluator 1.930000 0.080000 2.010000 ( 2.006648) 0.02006648 + CactusKevEvaluator 12.280000 0.100000 12.380000 ( 12.382839) 0.12382839 + CactusKevRubyEvaluator 14.290000 0.120000 14.410000 ( 14.404539) 0.14404539 + CactusKevBinarySearchEvaluator 26.210000 0.090000 26.300000 ( 26.298261) 0.26298261 + HurleyEvaluator 88.100000 1.260000 89.360000 ( 89.362515) 0.89362515 ## Install From f2af91d18ca10a610a03803422b35c2bcbf1d0d7 Mon Sep 17 00:00:00 2001 From: Jonas Schubert Erlandsson Date: Mon, 24 Aug 2015 19:46:41 +0200 Subject: [PATCH 8/9] Changes code bock style for time table to save space. --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d7307fb..ca630d6 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,15 @@ Plural evaluators may be installed and tested for comparative accuracy and effic **CactusKev2p2Evaluator** - Carrying lookup tables to the limit, this evaluator is based on the two-plus-two valuation optimization thread, using a monstrously large lookup table that represents a state machine for 7-card hands. Unlike the previous tables, it does not require any special processing beyond serially looking up (a single table index for each card) the cards in the hand to produce a hand valuation score. This runs significantly faster (40x) than the Hurley evaluator: - 7-card shootout (100,000 random hands) - user system total real ms per hand - CactusKev2p2Evaluator 1.930000 0.080000 2.010000 ( 2.006648) 0.02006648 - CactusKevEvaluator 12.280000 0.100000 12.380000 ( 12.382839) 0.12382839 - CactusKevRubyEvaluator 14.290000 0.120000 14.410000 ( 14.404539) 0.14404539 - CactusKevBinarySearchEvaluator 26.210000 0.090000 26.300000 ( 26.298261) 0.26298261 - HurleyEvaluator 88.100000 1.260000 89.360000 ( 89.362515) 0.89362515 +```text +7-card shootout (100,000 random hands) + user system total real ms per hand +CactusKev2p2Evaluator 1.930000 0.080000 2.010000 ( 2.006648) 0.02006648 +CactusKevEvaluator 12.280000 0.100000 12.380000 ( 12.382839) 0.12382839 +CactusKevRubyEvaluator 14.290000 0.120000 14.410000 ( 14.404539) 0.14404539 +CactusKevBinarySearchEvaluator 26.210000 0.090000 26.300000 ( 26.298261) 0.26298261 +HurleyEvaluator 88.100000 1.260000 89.360000 ( 89.362515) 0.89362515 +`` ## Install From 000add92eae7616f890d4f2bb0fcb3491c62f2ee Mon Sep 17 00:00:00 2001 From: Jonas Schubert Erlandsson Date: Mon, 24 Aug 2015 19:47:26 +0200 Subject: [PATCH 9/9] Adds missing code block delimiteer. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ca630d6..f4c0f08 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ CactusKevEvaluator 12.280000 0.100000 12.380000 ( 12.382839) CactusKevRubyEvaluator 14.290000 0.120000 14.410000 ( 14.404539) 0.14404539 CactusKevBinarySearchEvaluator 26.210000 0.090000 26.300000 ( 26.298261) 0.26298261 HurleyEvaluator 88.100000 1.260000 89.360000 ( 89.362515) 0.89362515 -`` +``` ## Install