Class: AcpcTableManager::MatchSlice
- Inherits:
-
Object
- Object
- AcpcTableManager::MatchSlice
- Includes:
- Mongoid::Document, Mongoid::Timestamps::Updated
- Defined in:
- lib/acpc_table_manager/match_slice.rb
Class Method Summary collapse
- .adjust_action_amount(action, round, match_state, game_def) ⇒ Object
-
.all_in(state, game_def) ⇒ Object
Over round.
- .amount_to_call(state, game_def) ⇒ Object
- .betting_sequence(match_state, game_def) ⇒ Object
-
.chip_contribution_after_calling(state, game_def) ⇒ Object
Over round.
- .from_players_at_the_table!(patt, match_has_ended, match) ⇒ Object
-
.minimum_wager_to(state, game_def) ⇒ Object
Over round.
-
.players(patt, player_names) ⇒ Array<Hash>
Each player hash should contain values for the following keys: ‘name’, ‘seat’ ‘chip_stack’ ‘chip_contributions’ ‘chip_balance’ ‘hole_cards’ ‘winnings’.
-
.pot_after_call(state, game_def) ⇒ Object
Over round.
- .pot_at_start_of_round(match_state, game_def) ⇒ Object
Instance Method Summary collapse
Class Method Details
.adjust_action_amount(action, round, match_state, game_def) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/acpc_table_manager/match_slice.rb', line 183 def self.adjust_action_amount(action, round, match_state, game_def) amount_to_over_hand = action.modifier if amount_to_over_hand.blank? action else amount_to_over_round = ( amount_to_over_hand.to_i - match_state.players(game_def)[ match_state.position_relative_to_dealer ].contributions_before(round).to_i ) "#{action[0]}#{amount_to_over_round}" end end |
.all_in(state, game_def) ⇒ Object
Over round
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/acpc_table_manager/match_slice.rb', line 153 def self.all_in(state, game_def) return 0 if state.hand_ended?(game_def) ( state.players(game_def)[state.next_to_act(game_def)].stack + ( state.players(game_def)[state.next_to_act(game_def)] .contributions[state.round] || 0 ) ).floor end |
.amount_to_call(state, game_def) ⇒ Object
165 166 167 168 169 |
# File 'lib/acpc_table_manager/match_slice.rb', line 165 def self.amount_to_call(state, game_def) return 0 if state.next_to_act(game_def).nil? state.players(game_def).amount_to_call(state.next_to_act(game_def)) end |
.betting_sequence(match_state, game_def) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/acpc_table_manager/match_slice.rb', line 56 def self.betting_sequence(match_state, game_def) sequence = '' match_state.betting_sequence(game_def).each_with_index do |actions_per_round, round| actions_per_round.each_with_index do |action, action_index| adjusted_action = adjust_action_amount( action, round, match_state, game_def ) sequence << if ( match_state.player_acting_sequence(game_def)[round][action_index].to_i == match_state.position_relative_to_dealer ) adjusted_action.capitalize else adjusted_action end end sequence << '/' unless round == match_state.betting_sequence(game_def).length - 1 end sequence end |
.chip_contribution_after_calling(state, game_def) ⇒ Object
Over round
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/acpc_table_manager/match_slice.rb', line 133 def self.chip_contribution_after_calling(state, game_def) return 0 unless state.next_to_act(game_def) ( ( state.players(game_def)[ state.next_to_act(game_def) ].contributions[state.round] || 0 ) + amount_to_call(state, game_def) ) end |
.from_players_at_the_table!(patt, match_has_ended, match) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/acpc_table_manager/match_slice.rb', line 32 def self.from_players_at_the_table!(patt, match_has_ended, match) match.slices.create!( hand_has_ended: patt.hand_ended?, match_has_ended: match_has_ended, seat_with_dealer_button: patt.dealer_player.seat.to_i, seat_next_to_act: if patt.next_player_to_act patt.next_player_to_act.seat.to_i end, state_string: patt.match_state.to_s, # Not necessary to be in the database, but more performant than processing on the # Rails server betting_sequence: betting_sequence(patt.match_state, patt.game_def), pot_at_start_of_round: pot_at_start_of_round(patt.match_state, patt.game_def).to_i, players: players(patt, match.player_names), minimum_wager_to: minimum_wager_to(patt.match_state, patt.game_def).to_i, chip_contribution_after_calling: chip_contribution_after_calling(patt.match_state, patt.game_def).to_i, pot_after_call: pot_after_call(patt.match_state, patt.game_def).to_i, all_in: all_in(patt.match_state, patt.game_def).to_i, is_users_turn_to_act: patt.users_turn_to_act?, legal_actions: patt.legal_actions.map { |action| action.to_s }, amount_to_call: amount_to_call(patt.match_state, patt.game_def).to_i ) end |
.minimum_wager_to(state, game_def) ⇒ Object
Over round
123 124 125 126 127 128 129 130 |
# File 'lib/acpc_table_manager/match_slice.rb', line 123 def self.minimum_wager_to(state, game_def) return 0 unless state.next_to_act(game_def) ( state.min_wager_by(game_def) + chip_contribution_after_calling(state, game_def) ).ceil end |
.players(patt, player_names) ⇒ Array<Hash>
Each player hash should contain values for the following keys: ‘name’, ‘seat’ ‘chip_stack’ ‘chip_contributions’ ‘chip_balance’ ‘hole_cards’ ‘winnings’
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/acpc_table_manager/match_slice.rb', line 99 def self.players(patt, player_names) player_names_queue = player_names.dup patt.players.map do |player| hole_cards = if !(player.hand.empty? || player.folded?) player.hand.to_acpc elsif player.folded? '' else '_' * patt.game_def.number_of_hole_cards end { 'name' => player_names_queue.shift, 'seat' => player.seat, 'chip_stack' => player.stack.to_i, 'chip_contributions' => player.contributions.map { |contrib| contrib.to_i }, 'chip_balance' => player.balance, 'hole_cards' => hole_cards, 'winnings' => player.winnings.to_f } end end |
.pot_after_call(state, game_def) ⇒ Object
Over round
146 147 148 149 150 |
# File 'lib/acpc_table_manager/match_slice.rb', line 146 def self.pot_after_call(state, game_def) return state.pot(game_def) if state.hand_ended?(game_def) state.pot(game_def) + state.players(game_def).amount_to_call(state.next_to_act(game_def)) end |
.pot_at_start_of_round(match_state, game_def) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/acpc_table_manager/match_slice.rb', line 81 def self.pot_at_start_of_round(match_state, game_def) return 0 if match_state.round == 0 match_state.players(game_def).inject(0) do |sum, pl| sum += pl.contributions[0..match_state.round - 1].inject(:+) end end |
Instance Method Details
#hand_ended? ⇒ Boolean
174 175 176 |
# File 'lib/acpc_table_manager/match_slice.rb', line 174 def hand_ended? self.hand_has_ended end |
#match_ended? ⇒ Boolean
177 178 179 |
# File 'lib/acpc_table_manager/match_slice.rb', line 177 def match_ended? self.match_has_ended end |
#users_turn_to_act? ⇒ Boolean
171 172 173 |
# File 'lib/acpc_table_manager/match_slice.rb', line 171 def users_turn_to_act? self.is_users_turn_to_act end |