Class: AcpcPokerTypes::PlayersAtTheTable
- Inherits:
-
Object
- Object
- AcpcPokerTypes::PlayersAtTheTable
- Defined in:
- lib/acpc_poker_types/players_at_the_table.rb
Instance Attribute Summary collapse
-
#game_def ⇒ Object
readonly
Returns the value of attribute game_def.
-
#match_state ⇒ Object
readonly
Returns the value of attribute match_state.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
Instance Method Summary collapse
- #big_blind_payer ⇒ Object
-
#dealer_player ⇒ Player
The player with the dealer button.
-
#hand_ended? ⇒ Boolean
true
if the hand has ended,false
otherwise. -
#initialize(game_def, seat = 0) ⇒ PlayersAtTheTable
constructor
A new instance of PlayersAtTheTable.
-
#legal_actions ⇒ Array
The set of legal actions for the currently acting player.
- #match_ended?(max_num_hands = nil) ⇒ Boolean
- #next_player_to_act ⇒ Object
-
#player_acting_sequence ⇒ Array<Array<Integer>>
The sequence of seats that acted, separated by round.
-
#player_acting_sequence_string ⇒ String
Player acting sequence as a string.
-
#position_relative_to_dealer(player) ⇒ Integer
The position relative to the dealer of the given player,
player
, indexed such that the player immediately to to the left of the dealer has aposition_relative_to_dealer
of zero. - #seat(pos_rel_dealer = users_position_relative_to_dealer) ⇒ Object
- #small_blind_payer ⇒ Object
- #update!(match_state) ⇒ Object
- #users_position_relative_to_dealer ⇒ Object
-
#users_turn_to_act? ⇒ Boolean
true
if it is the user’s turn to act,false
otherwise.
Constructor Details
#initialize(game_def, seat = 0) ⇒ PlayersAtTheTable
Returns a new instance of PlayersAtTheTable.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 38 def initialize(game_def, seat = 0) @players = game_def.number_of_players.times.map do |i| Player.new( Seat.new(i, game_def.number_of_players) ) end @game_def = game_def @seat = Seat.new(seat, game_def.number_of_players) @match_state = nil @match_has_ended = false end |
Instance Attribute Details
#game_def ⇒ Object (readonly)
Returns the value of attribute game_def.
31 32 33 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 31 def game_def @game_def end |
#match_state ⇒ Object (readonly)
Returns the value of attribute match_state.
31 32 33 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 31 def match_state @match_state end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
31 32 33 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 31 def players @players end |
Instance Method Details
#big_blind_payer ⇒ Object
87 88 89 90 91 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 87 def big_blind_payer @players.find do |plyr| position_relative_to_dealer(plyr) == @game_def.blinds.index(@game_def.blinds.max) end end |
#dealer_player ⇒ Player
Returns The player with the dealer button.
83 84 85 86 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 83 def dealer_player return Player.new(nil) unless @match_state @players.find { |player| position_relative_to_dealer(player) == @players.length - 1} end |
#hand_ended? ⇒ Boolean
Returns true
if the hand has ended, false
otherwise.
59 60 61 62 63 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 59 def hand_ended? return false unless @match_state @match_state.hand_ended? @game_def end |
#legal_actions ⇒ Array
Returns The set of legal actions for the currently acting player.
126 127 128 129 130 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 126 def legal_actions return [] unless @match_state @match_state.legal_actions(@game_def) end |
#match_ended?(max_num_hands = nil) ⇒ Boolean
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 65 def match_ended?(max_num_hands = nil) @match_has_ended ||= ( hand_ended? && ( ( max_num_hands && match_state.hand_number >= max_num_hands - 1 ) || ( match_state && match_state.stack_sizes && ( players.any? do |player| !((player.stack + player.winnings.to_f) > 0) end ) ) ) ) end |
#next_player_to_act ⇒ Object
101 102 103 104 105 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 101 def next_player_to_act return Player.new(nil) if @match_state.nil? || hand_ended? @players.find { |plyr| position_relative_to_dealer(plyr) == @match_state.next_to_act(@game_def) } end |
#player_acting_sequence ⇒ Array<Array<Integer>>
Returns The sequence of seats that acted, separated by round.
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 139 def player_acting_sequence return [[]] unless @match_state @match_state.player_acting_sequence(@game_def).map do |actions_per_round| next [] if actions_per_round.empty? actions_per_round.map do |pos_rel_dealer| seat(pos_rel_dealer) end end end |
#player_acting_sequence_string ⇒ String
Returns player acting sequence as a string.
133 134 135 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 133 def player_acting_sequence_string (player_acting_sequence.map { |per_round| per_round.join('') }).join('/') end |
#position_relative_to_dealer(player) ⇒ Integer
Returns The position relative to the dealer of the given player, player
, indexed such that the player immediately to to the left of the dealer has a position_relative_to_dealer
of zero.
121 122 123 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 121 def position_relative_to_dealer(player) (seat.seats_to(player) + users_position_relative_to_dealer) % @players.length end |
#seat(pos_rel_dealer = users_position_relative_to_dealer) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 151 def seat(pos_rel_dealer = users_position_relative_to_dealer) return @seat if pos_rel_dealer == users_position_relative_to_dealer Seat.new( @seat + Seat.new(users_position_relative_to_dealer, @game_def.number_of_players).seats_to(pos_rel_dealer), @game_def.number_of_players ) end |
#small_blind_payer ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 92 def small_blind_payer @players.find do |plyr| position_relative_to_dealer(plyr) == ( @game_def.blinds.index do |blind| blind < @game_def.blinds.max && blind > 0 end ) end end |
#update!(match_state) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 51 def update!(match_state) @match_has_ended = false @match_state = MatchState.new(match_state, @match_state, @game_def) update_players! end |
#users_position_relative_to_dealer ⇒ Object
160 161 162 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 160 def users_position_relative_to_dealer @match_state.position_relative_to_dealer end |
#users_turn_to_act? ⇒ Boolean
Returns true
if it is the user’s turn to act, false
otherwise.
108 109 110 111 112 |
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 108 def users_turn_to_act? return false if @match_state.nil? || hand_ended? next_player_to_act.seat == seat end |