Class: MatchView
Instance Attribute Summary collapse
-
#match ⇒ Object
readonly
Returns the value of attribute match.
Class Method Summary collapse
Instance Method Summary collapse
-
#all_in ⇒ Object
Over round.
- #amount_for_next_player_to_call ⇒ Object
- #balances ⇒ Object
- #betting_sequence ⇒ Object
- #betting_type_label ⇒ Object
-
#chip_contribution_for_next_player_after_calling ⇒ Object
Over round.
- #game_def ⇒ Object
- #hand_ended? ⇒ Boolean
-
#initialize(match_id) ⇒ MatchView
constructor
A new instance of MatchView.
- #legal_actions ⇒ Object
- #match_ended? ⇒ Boolean
-
#minimum_wager_to ⇒ Object
Over round.
- #no_limit? ⇒ Boolean
- #opponents ⇒ Object
- #opponents_sorted_by_position_from_user ⇒ Object
- #player_names ⇒ Object
-
#players ⇒ Array<Hash>
Each player hash should contain values for the following keys: ‘name’, ‘seat’ ‘chip_stack’ ‘chip_contributions’ ‘chip_balance’ ‘hole_cards’.
-
#pot_after_call ⇒ Object
Over round.
- #pot_at_start_of_round ⇒ Object
-
#pot_fraction_wager_to(fraction = 1) ⇒ Object
Over round.
- #slice ⇒ Object
- #state ⇒ Object
- #user ⇒ Object
- #user_contributions_in_previous_rounds ⇒ Object
-
#users_seat ⇒ Object
zero indexed.
- #users_turn_to_act? ⇒ Boolean
Constructor Details
Instance Attribute Details
#match ⇒ Object (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_in ⇒ Object
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_call ⇒ Object
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 |
#balances ⇒ Object
38 39 40 |
# File 'lib/match_view.rb', line 38 def balances @balances ||= slice.balances end |
#betting_sequence ⇒ Object
47 48 49 |
# File 'lib/match_view.rb', line 47 def betting_sequence @betting_sequence ||= slice.betting_sequence end |
#betting_type_label ⇒ Object
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_calling ⇒ Object
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_def ⇒ Object
44 45 46 |
# File 'lib/match_view.rb', line 44 def game_def @game_def ||= @match.game_def end |
#hand_ended? ⇒ 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 |
#legal_actions ⇒ Object
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
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_to ⇒ Object
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
41 42 43 |
# File 'lib/match_view.rb', line 41 def no_limit? @is_no_limit ||= @match.no_limit? end |
#opponents ⇒ Object
89 90 91 |
# File 'lib/match_view.rb', line 89 def opponents @opponents ||= compute_opponents end |
#opponents_sorted_by_position_from_user ⇒ Object
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_names ⇒ Object
31 32 33 |
# File 'lib/match_view.rb', line 31 def player_names @player_names ||= @match.player_names end |
#players ⇒ Array<Hash>
Each player hash should contain values for the following keys: ‘name’, ‘seat’ ‘chip_stack’ ‘chip_contributions’ ‘chip_balance’ ‘hole_cards’
81 82 83 84 85 |
# File 'lib/match_view.rb', line 81 def players return @players if @players @players = slice.players end |
#pot_after_call ⇒ Object
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_round ⇒ Object
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 |
#slice ⇒ Object
28 29 30 |
# File 'lib/match_view.rb', line 28 def slice @slice ||= @match.slices.first end |
#state ⇒ Object
25 26 27 |
# File 'lib/match_view.rb', line 25 def state @state ||= MatchState.parse slice.state_string end |
#user ⇒ Object
86 87 88 |
# File 'lib/match_view.rb', line 86 def user @user ||= players[users_seat] end |
#user_contributions_in_previous_rounds ⇒ Object
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_seat ⇒ Object
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
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 |