Module: Pokerstats

Included in:
HandClass
Defined in:
lib/pokerstats.rb,
lib/pokerstats/poker-edge.rb,
lib/pokerstats/hand_history.rb,
lib/pokerstats/hand_constants.rb,
lib/pokerstats/hand_statistics.rb,
lib/pokerstats/pokerstars_file.rb,
lib/pokerstats/stat_aggregator.rb,
lib/pokerstats/player_statistics.rb,
lib/pokerstats/hand_classification.rb,
lib/pokerstats/hand_statistics_api.rb,
lib/pokerstats/plugins/cash_statistics.rb,
lib/pokerstats/plugins/street_statistics.rb,
lib/pokerstats/plugins/aggression_statistics.rb,
lib/pokerstats/plugins/street_bet_statistics.rb,
lib/pokerstats/pokerstars_hand_history_parser.rb,
lib/pokerstats/plugins/blind_attack_statistics.rb,
lib/pokerstats/plugins/preflop_raise_statistics.rb,
lib/pokerstats/plugins/continuation_bet_statistics.rb

Defined Under Namespace

Modules: HandConstants, HandStatisticsAPI Classes: AggressionStatistics, BlindAttackStatistics, CashStatistics, ContinuationBetStatistics, HandClass, HandHistory, HandHistoryParseError, HandStatistics, PlayerStatistics, PokerEdge, PokerstarsFile, PokerstarsHandHistoryParser, PokerstarsTimeStringConverter, PreflopRaiseStatistics, StatAggregationCount, StatAggregator, StreetBetStatistics, StreetStatistics

Constant Summary collapse

CASH =
"[0-9$,.]+"

Instance Method Summary collapse

Instance Method Details

#class_index_from_class_string(class_string) ⇒ Object



44
45
46
47
48
# File 'lib/pokerstats/hand_classification.rb', line 44

def class_index_from_class_string(class_string)
  class_index_from_class_string!(class_string)
rescue
  nil
end

#class_index_from_class_string!(class_string) ⇒ Object

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pokerstats/hand_classification.rb', line 50

def class_index_from_class_string!(class_string)
raise ArgumentError, "class_string #{class_string.inspect} must be a String" unless class_string.kind_of?(String)
class_string.upcase!
first = Pokerstats::HandConstants::CARDS.index(class_string[0..0])
second = Pokerstats::HandConstants::CARDS.index(class_string[1..1])
first, second = second, first if first > second
raise ArgumentError, "class_string is malformed" if first.nil? || second.nil?
case class_string[2..2]
when "S","P"
  13*first+second
when "O",""
  13*second+first      
else raise ArgumentError, "class_string is malformed"
end
end

#class_index_from_hand_string(hand_string) ⇒ Object



3
4
5
6
7
# File 'lib/pokerstats/hand_classification.rb', line 3

def class_index_from_hand_string(hand_string)
  return class_index_from_hand_string!(hand_string)
rescue ArgumentError
  nil
end

#class_index_from_hand_string!(hand_string) ⇒ Object



9
10
11
# File 'lib/pokerstats/hand_classification.rb', line 9

def class_index_from_hand_string!(hand_string)
class_index_from_class_string!(class_string_from_hand_string!(hand_string))
end

#class_index_from_row_and_col(row, col) ⇒ Object



93
94
95
# File 'lib/pokerstats/hand_classification.rb', line 93

def class_index_from_row_and_col(row, col)
    row*13 + col
end

#class_string_from_class_index(class_index) ⇒ Object



66
67
68
69
70
# File 'lib/pokerstats/hand_classification.rb', line 66

def class_string_from_class_index(class_index)
  class_string_from_class_index!(class_index)
rescue ArgumentError
  nil
end

#class_string_from_class_index!(class_index) ⇒ Object

Raises:

  • (ArgumentError)


72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/pokerstats/hand_classification.rb', line 72

def class_string_from_class_index!(class_index)
raise ArgumentError, "class_index (#{class_index.inspect}) must be an integer between 0 and 168" unless class_index.kind_of? Integer and class_index.between?(0,168)
row, col = row_from_class_index(class_index), col_from_class_index(class_index)
case row <=> col
when 1
  Pokerstats::HandConstants::CARDS[col..col] + Pokerstats::HandConstants::CARDS[row..row] + "o"
when 0
  Pokerstats::HandConstants::CARDS[row..row]*2
when -1
  Pokerstats::HandConstants::CARDS[row..row] + Pokerstats::HandConstants::CARDS[col..col] + "s"
end
end

#class_string_from_hand_string(hand_string) ⇒ Object



13
14
15
16
17
# File 'lib/pokerstats/hand_classification.rb', line 13

def class_string_from_hand_string(hand_string)
  class_string_from_hand_string!(hand_string)
rescue
  nil
end

#class_string_from_hand_string!(hand_string) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pokerstats/hand_classification.rb', line 19

def class_string_from_hand_string!(hand_string)
raise ArgumentError, "hand_string '#{hand_string}' must be a String" unless hand_string.kind_of?(String)
hand_string = hand_string.gsub(/ /,'')
hand_string = hand_string.upcase
raise ArgumentError, "hand_string '#{hand_string}' must have 4 non-blank characters" unless hand_string.size==4
first_rank, first_suit, second_rank, secondSuit = *hand_string.split('')
raise ArgumentError, "hand_string #{hand_string.inspect} suit characters #{first_suit.inspect} and #{secondSuit.inspect} must be from CDHS" unless "CDHS".include?(first_suit) && "CDHS".include?(secondSuit)
first_rank_index, second_rank_index = Pokerstats::HandConstants::CARDS.index(first_rank), Pokerstats::HandConstants::CARDS.index(second_rank) 
raise ArgumentError, "hand_string '#{hand_string}' rank characters must be from AKQJT98765432" if first_rank_index.nil? || second_rank_index.nil?
if first_rank==second_rank
  raise ArgumentError, "hand_string '#{hand_string}' cards must be different" if first_suit == secondSuit || !"CDHS".include?(first_suit)
  first_rank*2
else
  if first_rank_index > second_rank_index
    result = first_rank + second_rank
  else
    result = second_rank + first_rank
  end
  if first_suit == secondSuit
    result += "s"
  end
  result
end
end

#col_from_class_index(classIndex) ⇒ Object



89
90
91
# File 'lib/pokerstats/hand_classification.rb', line 89

def col_from_class_index(classIndex)
classIndex % 13
end

#row_from_class_index(classIndex) ⇒ Object



85
86
87
# File 'lib/pokerstats/hand_classification.rb', line 85

def row_from_class_index(classIndex)
classIndex / 13
end