rora 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Copyright (c) 2012 Brandon John Grenier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is furnished
8
+ to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
17
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,258 @@
1
+ [![Build Status](https://secure.travis-ci.org/BrandonJohnGrenier/Rora.png?branch=master)](http://travis-ci.org/BrandonJohnGrenier/Rora)
2
+
3
+
4
+ ## Suits and Ranks
5
+
6
+
7
+ ### Suits
8
+ A complete deck of 52 cards will contain exactly four different suits - spades, hearts, clubs and diamonds. Each suit instance along with the equivalent character value are shown below:
9
+
10
+ Suit::SPADE // 'S'
11
+ Suit::HEART // 'H'
12
+ Suit::CLUB // 'C'
13
+ Suit::DIAMOND // 'D'
14
+
15
+
16
+ ### Ranks
17
+ A complete deck of 52 cards will contain exactly thirteen ranks - numerical values 2 -> 10 inclusive, plus four non-numerical cards (Jack, Queen, King, Ace). Instances along with equivalent character values are shown below:
18
+
19
+ Rank::ACE // 'A'
20
+ Rank::KING // 'K'
21
+ Rank::QUEEN // 'Q'
22
+ Rank::JACK // 'J'
23
+ Rank::TEN // 'T'
24
+ Rank::NINE // '9'
25
+ Rank::EIGHT // '8'
26
+ Rank::SEVEN // '7'
27
+ Rank::SIX // '6'
28
+ Rank::FIVE // '5'
29
+ Rank::FOUR // '4'
30
+ Rank::THREE // '3'
31
+ Rank::TWO // '2'
32
+
33
+ ## Cards
34
+
35
+ ### Overview
36
+ A playing card is constructed with one suit and one rank. A card can be created in by using the Suit and Rank classes as described above, or their equivalent character values.
37
+
38
+ # Example 1: Creating a card with Rank and Suit instances.
39
+ card = Card.new Rank::ACE, Suit::SPADE
40
+
41
+ # Example 2: Creating a card with rank and suit values.
42
+ card = Card.new "AS"
43
+
44
+ # Example 3: Rank and suit values are case insensitive.
45
+ card = Card.new "as"
46
+
47
+ ### Creating multiple cards at once
48
+
49
+ You can create multiple cards at once by using the to_cards class method. The to_cards takes a series suit-rank characters seperated by commas or white spaces and returns an Array of Cards.
50
+
51
+ # Example 1: Create an array of cards by providing a comma-seperated string.
52
+ cards = Card.to_cards "AS,KS,QS,JS"
53
+
54
+ # Example 2: Create an array of cards by providing a space-sepearated string.
55
+ cards = Card.to_cards "AS KS QS JS"
56
+
57
+ # Example 3: Rank and suit values are case insensitive.
58
+ cards = Card.to_cards "as KS qs Js Ts"
59
+
60
+ ## Hands
61
+
62
+ ### Overview
63
+ A hand consists of exactly five cards, and can be constructed by providing an Array of cards or an equivalent sequence of suit-rank character values.
64
+
65
+ # Example 1: Creating a hand with a comma-seperated string.
66
+ hand = Hand.new "AS,KS,QS,JS,TS"
67
+
68
+ # Example 2: Creating a hand with a space-seperated string.
69
+ hand = Hand.new "AS KS QS JS TS"
70
+
71
+ # Example 3: Creating a hand with an Array of cards.
72
+ hand = Hand.new [Card.new("AS"), Card.new("KS"), Card.new("QS"), Card.new("JS"), Card.new("TS")]
73
+
74
+ # Example 4: Creating a hand with an Array of cards, using Card.to_cards
75
+ hand = Hand.new Card.to_cards("AS,KS,QS,JS,TS")
76
+
77
+ ### Hand Score
78
+
79
+ Each hand in poker has a rank, or score. While many software libraries provide the capability to calculate hand scores, rora implicitly provides you with a score for each hand.
80
+
81
+ # Example 1: A Royal Flush is the highest scoring poker hand.
82
+ royal_flush = Hand.new "AS,KS,QS,JS,TS"
83
+
84
+ puts royal_flush.score => 1
85
+ puts royal_flush.name => 'Royal Flush'
86
+ puts royal_flush.probability => 0.0015 // Probability of receiving any Royal Flush
87
+
88
+ # Example 2: A Seven-High High Card is the lowest scoring poker hand.
89
+ seven_high = Hand.new "7S,5H,4H,3C,2C"
90
+
91
+ puts seven_high.score => 7642
92
+ puts seven_high.name => 'High Card'
93
+ puts seven_high.probability => 0.50 // Probability of receiving any High Card
94
+
95
+ ### Hand Detection
96
+
97
+ You can query a hand to determine what kind of hand it is.
98
+
99
+ # Example 1: Testing for a straight flush
100
+ puts Hand.new("AS,KS,QS,JS,TS").straight_flush? => true
101
+ puts Hand.new("AS,KS,QS,JS,TS").two_pair? => false
102
+
103
+ Hand type detection extends to the following methods:
104
+
105
+ - flush?
106
+ - straight_flush?
107
+ - four_of_a_kind?
108
+ - full_house?
109
+ - straight?
110
+ - three_of_a_kind?
111
+ - two_pair?
112
+ - one_pair?
113
+ - high_card?
114
+
115
+ ## Starting Hands
116
+
117
+ Beyond the code samples presented below, the following links provide more information about [texas hold'em starting hands](http://www.moralesce.com/2012/01/21/holdem-starting-hands/) and [poker hand evaluation](http://www.moralesce.com/2011/11/26/poker-hand-evaluation/).
118
+
119
+ ### Overview
120
+ A starting hand is also referred to as a players pocket cards, or hole cards. A starting hand consists of exactly two cards held by one player, unseen by opponents. Starting hands can be created by proiding an Array of Cards of an equivalent sequence of suit-rank character values.
121
+
122
+ # Example 1: Creating a starting hand with a comma-seperated string.
123
+ starting_hand = StartingHand.new "AS,KS"
124
+
125
+ # Example 2: Creating a starting hand with a space-seperated string.
126
+ starting_hand = StartingHand.new "AS KS"
127
+
128
+ # Example 3: Creating a hand with an Array of cards.
129
+ starting_hand = StartingHand.new [Card.new("AS"), Card.new("KS")]
130
+
131
+ # Example 4: Creating a starting hand with an Array of cards, using Card.to_cards
132
+ starting_hand = StartingHand.new Card.to_cards("AS,KS")
133
+
134
+ ### Creating an array of all starting hands
135
+
136
+ # Returns an array of all 1324 starting hands.
137
+ all = StartingHand.all_starting_hands
138
+
139
+
140
+ ### Creating an array of unique starting hands
141
+
142
+ # Returns an array of 169 unique starting hands
143
+ unique = StartingHand.unique_starting_hands
144
+
145
+ ## Decks
146
+
147
+ ### Overview
148
+ A deck consists of 52 playing cards.
149
+
150
+ # Creates a new Deck
151
+ deck = Deck.new
152
+
153
+ # A new deck will have 52 playing cards
154
+ cards = deck.cards
155
+ puts cards.size => 52
156
+
157
+ # You can also get size of the deck from the deck itself.
158
+ puts deck.size => 52
159
+
160
+ ### Shuffling and Dealing
161
+ When a deck is created the cards are well organized. The deck should be shuffled to randomize the order of the cards before they are dealt.
162
+
163
+ # Shuffling the deck
164
+ deck.shuffle
165
+
166
+ # The deal method returns one card from the deck.
167
+ puts deck.size => 52
168
+ card = deck.deal
169
+ puts deck.size => 51
170
+
171
+ ### Removing Cards
172
+ The remove method takes a variety of arguments.
173
+
174
+ # Removes a single card from the deck
175
+ deck.remove Card.new("AS")
176
+
177
+ # Removes a single card from the deck
178
+ deck.remove "AS"
179
+
180
+ # Removes multiple cards from the deck
181
+ deck.remove "AS,KS,QS,JS,TS"
182
+
183
+ # Removes multiple cards from the deck
184
+ deck.remove [Card.new("AS"), Card.new("KS"), Card.new("QS")]
185
+
186
+ # Removes a starting hand from the deck
187
+ starting_hand = StartingHand.new "AS, KS"
188
+ deck.remove starting_hand
189
+
190
+ ### Inspecting the Deck
191
+ You can query the deck to determine whether it contains a specific card or at least one card in a group.
192
+
193
+ # Determines if the Ace of Spades is in the deck.
194
+ deck.contains Card.new("AS")
195
+
196
+ # Determines if the Ace of Spades is in the deck.
197
+ deck.contains "AS"
198
+
199
+ # Determines if any Ace is in the deck.
200
+ deck.contains [Card.new("AS"), Card.new("AH"), Card.new("AD"), Card.new("AC")]
201
+
202
+ # Determines if any Ace is in the deck.
203
+ deck.contains "AS,AH,AD,AC"
204
+
205
+
206
+ ### Combinations
207
+ The combination method allows you to enumerate through card subsets. Given a combination value greater than 1, the method will return a two-dimensional array.
208
+
209
+
210
+ # Chooses every possible 2 card combination from the deck. Assuming the deck contains 52
211
+ # cards, this example will return 1324 2-card combinations.
212
+ cards = deck.combination 2
213
+
214
+ # Chooses every possible 5 card combination from the deck. Assuming the deck contains 52
215
+ # cards, this example will return 2,598,960 5-card combinations.
216
+ cards = deck.combination 5
217
+
218
+ ## Boards
219
+
220
+ ### Overview
221
+ A board represents the logical table area where community cards are dealt. A board can be setup with either 0, 3, 4 or 5 cards to represent and empty board, the flop, turn, or river (respectively).
222
+
223
+ # Creates an empty board.
224
+ board = Board.new
225
+
226
+ # Creates a board with the flop.
227
+ board = Board.new "AS,KS,QS"
228
+
229
+ # Creates a board with the flop and turn.
230
+ board = Board.new "KS,QS,JS,AS"
231
+
232
+ # Create a board with the flop, turn and river cards.
233
+ board = Board.new "KS,QS,7H,4C,3H"
234
+
235
+ ### Subsequent Betting Rounds
236
+ An empty board can be populated afterwads.
237
+
238
+ board = Board.new
239
+ board.flop = "AS,KS,QS"
240
+ board.turn = "4D"
241
+ board.river = "3D"
242
+
243
+ puts board.size => 5
244
+
245
+ ### Inspecting the Board
246
+ You can query the board to determine whether it contains a specific card or at least one card in a group.
247
+
248
+ # Determines if the Ace of Spades is on the board.
249
+ board.contains Card.new("AS")
250
+
251
+ # Determines if the Ace of Spades is on the board.
252
+ board.contains "AS"
253
+
254
+ # Determines if any Ace is on the board.
255
+ board.contains [Card.new("AS"), Card.new("AH"), Card.new("AD"), Card.new("AC")]
256
+
257
+ # Determines if any Ace is on the board.
258
+ board.contains "AS,AH,AD,AC"
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+
2
+ task :default => :test
3
+
4
+ task :test do
5
+ require 'rake/testtask'
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.test_files = FileList['test/**/*.rb']
9
+ t.verbose = true
10
+ end
11
+ end
12
+