Class: AcpcTableManager::MatchView

Inherits:
SimpleDelegator
  • Object
show all
Includes:
AcpcPokerTypes
Defined in:
lib/acpc_table_manager/match_view.rb

Constant Summary collapse

DEFAULT_WAIT_FOR_SLICE_TIMEOUT =

seconds

0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(match_id, slice_index = nil, load_previous_messages: false, timeout: DEFAULT_WAIT_FOR_SLICE_TIMEOUT) ⇒ MatchView

Returns a new instance of MatchView.

Raises:

  • (StandardError)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/acpc_table_manager/match_view.rb', line 32

def initialize(match_id, slice_index = nil, load_previous_messages: false, timeout: DEFAULT_WAIT_FOR_SLICE_TIMEOUT)
  @match = Match.find(match_id)
  super @match

  @messages_to_display = []

  @slice_index = slice_index || @match.last_slice_viewed

  raise StandardError.new("Illegal slice index: #{@slice_index}") unless @slice_index >= 0

  unless @slice_index < @match.slices.length
    if timeout > 0
      Timeout.timeout(timeout, UnableToFindNextSlice) do
        while @slice_index >= @match.slices.length do
          sleep 0.5
          @match = Match.find(match_id)
        end
      end
      super @match
    else
      raise UnableToFindNextSlice
    end
  end

  @messages_to_display = slice.messages

  @loaded_previous_messages_ = false

  load_previous_messages! if load_previous_messages
end

Instance Attribute Details

#matchObject (readonly)

Returns the value of attribute match.



19
20
21
# File 'lib/acpc_table_manager/match_view.rb', line 19

def match
  @match
end

#messages_to_displayObject

Returns the value of attribute messages_to_display.



19
20
21
# File 'lib/acpc_table_manager/match_view.rb', line 19

def messages_to_display
  @messages_to_display
end

#slice_indexObject (readonly)

Returns the value of attribute slice_index.



19
20
21
# File 'lib/acpc_table_manager/match_view.rb', line 19

def slice_index
  @slice_index
end

Class Method Details

.chip_contributions_in_previous_rounds(player, round) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/acpc_table_manager/match_view.rb', line 22

def self.chip_contributions_in_previous_rounds(player, round)
  if round > 0
    player['chip_contributions'][0..round-1].inject(:+)
  else
    0
  end
end

Instance Method Details

#all_inObject

Over round



147
148
149
# File 'lib/acpc_table_manager/match_view.rb', line 147

def all_in
  @all_in ||= slice.all_in
end

#amount_for_next_player_to_callObject



111
112
113
# File 'lib/acpc_table_manager/match_view.rb', line 111

def amount_for_next_player_to_call
  @amount_for_next_player_to_call ||= slice.amount_to_call
end

#betting_sequenceObject



70
# File 'lib/acpc_table_manager/match_view.rb', line 70

def betting_sequence() slice.betting_sequence end

#betting_type_labelObject



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/acpc_table_manager/match_view.rb', line 151

def betting_type_label
  if @betting_type_label.nil?
    @betting_type_label = if no_limit?
      'nolimit'
    else
     'limit'
    end
  end

  @betting_type_label
end

#chip_contribution_for_next_player_after_callingObject

Over round



116
117
118
# File 'lib/acpc_table_manager/match_view.rb', line 116

def chip_contribution_for_next_player_after_calling
  @chip_contribution_for_next_player_after_calling ||= slice.chip_contribution_after_calling
end

#hand_ended?Boolean

Returns:

  • (Boolean)


72
# File 'lib/acpc_table_manager/match_view.rb', line 72

def hand_ended?() slice.hand_ended? end


75
76
77
78
79
# File 'lib/acpc_table_manager/match_view.rb', line 75

def legal_actions
  slice.legal_actions.map do |action|
    AcpcPokerTypes::PokerAction.new(action)
  end
end

#load_previous_messages!(index = @slice_index) ⇒ Object



163
164
165
166
167
168
169
# File 'lib/acpc_table_manager/match_view.rb', line 163

def load_previous_messages!(index = @slice_index)
  @messages_to_display = slices[0...index].inject([]) do |messages, s|
    messages += s.messages
  end + @messages_to_display
  @loaded_previous_messages_ = true
  self
end

#loaded_previous_messages?Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/acpc_table_manager/match_view.rb', line 171

def loaded_previous_messages?
  @loaded_previous_messages_
end

#match_ended?Boolean

Returns:

  • (Boolean)


73
# File 'lib/acpc_table_manager/match_view.rb', line 73

def match_ended?() slice.match_ended? end

#minimum_wager_toObject

Over round



121
122
123
# File 'lib/acpc_table_manager/match_view.rb', line 121

def minimum_wager_to
  @minimum_wager_to ||= slice.minimum_wager_to
end

#opponentsObject



98
99
100
# File 'lib/acpc_table_manager/match_view.rb', line 98

def opponents
  @opponents ||= compute_opponents
end

#opponents_sorted_by_position_from_userObject



101
102
103
104
105
106
107
108
109
110
# File 'lib/acpc_table_manager/match_view.rb', line 101

def opponents_sorted_by_position_from_user
  @opponents_sorted_by_position_from_user ||= opponents.sort_by do |opp|
    Seat.new(
      opp['seat'],
      players.length
    ).seats_from(
      users_seat
    )
  end
end

#playersArray<Hash>

Each player hash should contain values for the following keys: ‘name’, ‘seat’ ‘chip_stack’ ‘chip_contributions’ ‘chip_balance’ ‘hole_cards’

Returns:

  • (Array<Hash>)

    Player information ordered by seat.



90
91
92
93
94
# File 'lib/acpc_table_manager/match_view.rb', line 90

def players
  return @players if @players

  @players = slice.players
end

#pot_after_callObject

Over round



126
127
128
# File 'lib/acpc_table_manager/match_view.rb', line 126

def pot_after_call
  @pot_after_call ||= slice.pot_after_call
end

#pot_at_start_of_roundObject



71
# File 'lib/acpc_table_manager/match_view.rb', line 71

def pot_at_start_of_round() slice.pot_at_start_of_round end

#pot_fraction_wager_to(fraction = 1) ⇒ Object

Over round



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/acpc_table_manager/match_view.rb', line 131

def pot_fraction_wager_to(fraction=1)
  return 0 if hand_ended?

  [
    [
      (
        fraction * pot_after_call +
        chip_contribution_for_next_player_after_calling
      ),
      minimum_wager_to
    ].max,
    all_in
  ].min.floor
end

#sliceObject



66
# File 'lib/acpc_table_manager/match_view.rb', line 66

def slice() slices[@slice_index] end

#stateObject



65
# File 'lib/acpc_table_manager/match_view.rb', line 65

def state() @state ||= MatchState.parse slice.state_string end

#userObject



95
96
97
# File 'lib/acpc_table_manager/match_view.rb', line 95

def user
  @user ||= players[users_seat]
end

#user_contributions_in_previous_roundsObject



62
63
64
# File 'lib/acpc_table_manager/match_view.rb', line 62

def user_contributions_in_previous_rounds
  self.class.chip_contributions_in_previous_rounds(user, state.round)
end

#users_seatObject

zero indexed



69
# File 'lib/acpc_table_manager/match_view.rb', line 69

def users_seat() @users_seat ||= @match.seat - 1 end

#users_turn_to_act?Boolean

Returns:

  • (Boolean)


74
# File 'lib/acpc_table_manager/match_view.rb', line 74

def users_turn_to_act?() slice.users_turn_to_act? end