Class: MatchView

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(match_id) ⇒ MatchView

Returns a new instance of MatchView.



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

def initialize(match_id)
  @match = Match.find(match_id)
end

Instance Attribute Details

#matchObject (readonly)

Returns the value of attribute match.



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

def match
  @match
end

Class Method Details

.chip_contributions_in_previous_rounds(player, round) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/match_view.rb', line 11

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



138
139
140
# File 'lib/match_view.rb', line 138

def all_in
  @all_in ||= slice.all_in
end

#amount_for_next_player_to_callObject



102
103
104
# File 'lib/match_view.rb', line 102

def amount_for_next_player_to_call
  @amount_for_next_player_to_call ||= slice.amount_to_call
end

#balancesObject



38
39
40
# File 'lib/match_view.rb', line 38

def balances
  @balances ||= slice.balances
end

#betting_sequenceObject



47
48
49
# File 'lib/match_view.rb', line 47

def betting_sequence
  @betting_sequence ||= slice.betting_sequence
end

#betting_type_labelObject



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/match_view.rb', line 142

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



107
108
109
# File 'lib/match_view.rb', line 107

def chip_contribution_for_next_player_after_calling
  @chip_contribution_for_next_player_after_calling ||= slice.chip_contribution_after_calling
end

#game_defObject



44
45
46
# File 'lib/match_view.rb', line 44

def game_def
  @game_def ||= @match.game_def
end

#hand_ended?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/match_view.rb', line 53

def hand_ended?
  @hand_has_ended = slice.hand_ended? if @hand_has_ended.nil?

  @hand_has_ended
end


68
69
70
# File 'lib/match_view.rb', line 68

def legal_actions
  @legal_actions ||= slice.legal_actions.map { |action| AcpcPokerTypes::PokerAction.new(action) }
end

#match_ended?Boolean

Returns:

  • (Boolean)


58
59
60
61
62
# File 'lib/match_view.rb', line 58

def match_ended?
  @match_has_ended = slice.match_ended? if @match_has_ended.nil?

  @match_has_ended
end

#minimum_wager_toObject

Over round



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

def minimum_wager_to
  @minimum_wager_to ||= slice.minimum_wager_to
end

#no_limit?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/match_view.rb', line 41

def no_limit?
  @is_no_limit ||= @match.no_limit?
end

#opponentsObject



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

def opponents
  @opponents ||= compute_opponents
end

#opponents_sorted_by_position_from_userObject



92
93
94
95
96
97
98
99
100
101
# File 'lib/match_view.rb', line 92

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

#player_namesObject



31
32
33
# File 'lib/match_view.rb', line 31

def player_names
  @player_names ||= @match.player_names
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.



81
82
83
84
85
# File 'lib/match_view.rb', line 81

def players
  return @players if @players

  @players = slice.players
end

#pot_after_callObject

Over round



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

def pot_after_call
  @pot_after_call ||= slice.pot_after_call
end

#pot_at_start_of_roundObject



50
51
52
# File 'lib/match_view.rb', line 50

def pot_at_start_of_round
  @pot_at_start_of_round ||= slice.pot_at_start_of_round
end

#pot_fraction_wager_to(fraction = 1) ⇒ Object

Over round



122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/match_view.rb', line 122

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



28
29
30
# File 'lib/match_view.rb', line 28

def slice
  @slice ||= @match.slices.first
end

#stateObject



25
26
27
# File 'lib/match_view.rb', line 25

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

#userObject



86
87
88
# File 'lib/match_view.rb', line 86

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

#user_contributions_in_previous_roundsObject



22
23
24
# File 'lib/match_view.rb', line 22

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

#users_seatObject

zero indexed



35
36
37
# File 'lib/match_view.rb', line 35

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

#users_turn_to_act?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
# File 'lib/match_view.rb', line 63

def users_turn_to_act?
  @is_users_turn_to_act = slice.users_turn_to_act? if @is_users_turn_to_act.nil?

  @is_users_turn_to_act
end