Class: AcpcPokerTypes::PlayersAtTheTable

Inherits:
Object
  • Object
show all
Defined in:
lib/acpc_poker_types/players_at_the_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game_def, seat = 0) ⇒ PlayersAtTheTable

Returns a new instance of PlayersAtTheTable.

Parameters:

  • game_def (GameDefinition)

    The game definition for the match these players are playing

  • seat (#to_i) (defaults to: 0)

    The user’s seat. Defaults to zero.



38
39
40
41
42
43
44
45
46
47
# 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
end

Instance Attribute Details

#game_defObject (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_stateObject (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

#playersObject (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_payerObject



68
69
70
71
72
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 68

def big_blind_payer
  @players.find do |plyr|
    position_relative_to_dealer(plyr) == @game_def.blinds.index(@game_def.blinds.max)
  end
end

#dealer_playerPlayer

Returns The player with the dealer button.

Returns:

  • (Player)

    The player with the dealer button.



64
65
66
67
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 64

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.

Returns:

  • (Boolean)

    true if the hand has ended, false otherwise.



57
58
59
60
61
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 57

def hand_ended?
  return false unless @match_state

  @match_state.hand_ended? @game_def
end

Returns The set of legal actions for the currently acting player.

Returns:

  • (Array)

    The set of legal actions for the currently acting player.



107
108
109
110
111
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 107

def legal_actions
  return [] unless @match_state

  @match_state.legal_actions(@game_def)
end

#next_player_to_actObject



82
83
84
85
86
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 82

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_sequenceArray<Array<Integer>>

Returns The sequence of seats that acted, separated by round.

Returns:

  • (Array<Array<Integer>>)

    The sequence of seats that acted, separated by round.



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 120

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_stringString

Returns player acting sequence as a string.

Returns:

  • (String)

    player acting sequence as a string.



114
115
116
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 114

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.

Parameters:

  • player (Integer)

    The player of which the position relative to the dealer is desired.

Returns:

  • (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 a position_relative_to_dealer of zero.



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

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



132
133
134
135
136
137
138
139
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 132

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_payerObject



73
74
75
76
77
78
79
80
81
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 73

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

Parameters:

  • match_state (MatchState)

    The next match state.



50
51
52
53
54
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 50

def update!(match_state)
  @match_state = MatchState.new(match_state, @match_state, @game_def)

  update_players!
end

#users_position_relative_to_dealerObject



141
142
143
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 141

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.

Returns:

  • (Boolean)

    true if it is the user’s turn to act, false otherwise.



89
90
91
92
93
# File 'lib/acpc_poker_types/players_at_the_table.rb', line 89

def users_turn_to_act?
  return false if @match_state.nil? || hand_ended?

  next_player_to_act.seat == seat
end