Class: AcpcPokerTypes::DealerData::HandResults

Inherits:
Object
  • Object
show all
Defined in:
lib/acpc_poker_types/dealer_data/hand_results.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(acpc_log_statements, player_names, game_def_directory, num_hands = nil) ⇒ HandResults

Returns a new instance of HandResults.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/acpc_poker_types/dealer_data/hand_results.rb', line 55

def initialize(acpc_log_statements, player_names, game_def_directory, num_hands=nil)
  @final_score = nil
  @match_def = nil

  @data = acpc_log_statements.inject([]) do |accumulating_data, log_line|
    if @match_def.nil?
      @match_def = AcpcPokerTypes::DealerData::MatchDefinition.parse(log_line, player_names, game_def_directory)
    else
      parsed_message = AcpcPokerTypes::DealerData::HandResults.parse_state(log_line)
      if parsed_message
        # Yes, this causes one more result to be parsed than is saved as long as
        # the number of hands is less than the total number in the log, but this
        # keeps behavior consistent between this class and ActionMessages.
        break accumulating_data if accumulating_data.length == num_hands
        accumulating_data << parsed_message
      else
        @final_score = AcpcPokerTypes::DealerData::HandResults.parse_score(log_line) unless @final_score
      end
    end

    accumulating_data
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/acpc_poker_types/dealer_data/hand_results.rb', line 6

def data
  @data
end

#final_scoreObject (readonly)

Returns the value of attribute final_score.



6
7
8
# File 'lib/acpc_poker_types/dealer_data/hand_results.rb', line 6

def final_score
  @final_score
end

#match_defObject (readonly)

Returns the value of attribute match_def.



6
7
8
# File 'lib/acpc_poker_types/dealer_data/hand_results.rb', line 6

def match_def
  @match_def
end

Class Method Details

.parse_file(acpc_log_file_path, player_names, game_def_directory, num_hands = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/acpc_poker_types/dealer_data/hand_results.rb', line 42

def self.parse_file(
  acpc_log_file_path,
  player_names,
  game_def_directory,
  num_hands=nil
)
   AcpcPokerTypes::DealerData::LogFile.open(acpc_log_file_path, 'r') do |file|
     AcpcPokerTypes::DealerData::HandResults.parse file, player_names, game_def_directory, num_hands
  end
end

.parse_score(score_string) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/acpc_poker_types/dealer_data/hand_results.rb', line 25

def self.parse_score(score_string)
  if score_string.strip.match(
    /^SCORE:([\d\-\.|]+):(.+)$/
    )

    stack_changes = $1.split '|'
    players = $2.split '|'

    players.each_index.inject({}) do |player_results, j|
       player_results[players[j].to_sym] = stack_changes[j].to_f
       player_results
    end
  else
    nil
  end
end

.parse_state(state_string) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/acpc_poker_types/dealer_data/hand_results.rb', line 8

def self.parse_state(state_string)
  if state_string.strip.match(
    /^STATE:\d+:[cfr\d\/]+:[^:]+:([\d\-\.|]+):(.+)$/
    )

    stack_changes = $1.split '|'
    players = $2.split '|'

    players.each_index.inject({}) do |player_results, j|
       player_results[players[j].to_sym] = stack_changes[j].to_f
       player_results
    end
  else
    nil
  end
end