-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflush_evaluator.rb
43 lines (38 loc) · 972 Bytes
/
flush_evaluator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module RangeTools
module FlushEvaluator
extend self
def evalFlush(twoCardHand, board)
fullHand, board = prepareForFlush(twoCardHand, board)
{
fullHand: flushStrength(fullHand),
board: flushStrength(board)
}
end
private
def flushStrength(hand)
suitBuckets = buildSuitBuckets(hand)
found = nil
suitBuckets.each_pair do |suit, count|
if count > 4
found = :flush
elsif count > 3
found = :flush_draw
end
end
found
end
def buildSuitBuckets(fullHand)
fullHand.inject({}) do |suitBuckets, suit|
suitBuckets[suit] ||= 0
suitBuckets[suit] += 1
suitBuckets
end
end
def prepareForFlush(twoCardHand, board)
twoCardHand = twoCardHand.collect {|card| card[:suit]}
board = board.collect {|card| card[:suit]}
fullHand = (twoCardHand + board)
[fullHand, board]
end
end
end