Class: AcpcPokerTypes::Player

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, seat, chip_stack) ⇒ Player

TODO:

These comments don’t work as expected

Returns a new instance of Player.

Parameters:

  • name (String)

    This players name.

  • seat (Integer)

    (see #seat)

  • chip_stack (#to_i)

    (see #chip_stack)



63
64
65
66
67
68
69
70
71
# File 'lib/acpc_poker_types/player.rb', line 63

def initialize(name, seat, chip_stack)
  @name = name
  @seat = seat
  @chip_balance = 0
  @chip_stack = chip_stack
  @chip_contributions = [0]

  @actions_taken_this_hand = [[]]
end

Instance Attribute Details

#actions_taken_this_handArray<Array<String>> (readonly)

Returns The list of actions this player has taken in the current hand, separated by round.

Returns:

  • (Array<Array<String>>)

    The list of actions this player has taken in the current hand, separated by round.



55
56
57
# File 'lib/acpc_poker_types/player.rb', line 55

def actions_taken_this_hand
  @actions_taken_this_hand
end

#chip_balanceInteger (readonly)

Returns The amount this player has won or lost in the current match. During a hand, this is a projected amount assuming that this player loses. Positive amounts are winnings, negative amounts are losses.

Returns:

  • (Integer)

    The amount this player has won or lost in the current match. During a hand, this is a projected amount assuming that this player loses. Positive amounts are winnings, negative amounts are losses.



46
47
48
# File 'lib/acpc_poker_types/player.rb', line 46

def chip_balance
  @chip_balance
end

#chip_contributionsArray<AcpcPokerTypes::ChipStack> (readonly)

Returns This player’s contribution to the pot in the current hand, organized by round.

Returns:



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

def chip_contributions
  @chip_contributions
end

#chip_stackAcpcPokerTypes::ChipStack (readonly)

Returns This player’s chip stack.

Returns:



37
38
39
# File 'lib/acpc_poker_types/player.rb', line 37

def chip_stack
  @chip_stack
end

#hole_cardsHand (readonly)

Returns This player’s hole cards or nil if this player is not holding cards.

Examples:

An ace of diamonds and a 4 of clubs is represented as

'Ad4c'

Returns:

  • (Hand)

    This player’s hole cards or nil if this player is not holding cards.



51
52
53
# File 'lib/acpc_poker_types/player.rb', line 51

def hole_cards
  @hole_cards
end

#nameString (readonly)

Returns The name of this player.

Returns:

  • (String)

    The name of this player.



30
31
32
# File 'lib/acpc_poker_types/player.rb', line 30

def name
  @name
end

#seatInteger (readonly)

Returns This player’s seat. This is a 0 indexed number that represents the order that this player joined the dealer.

Returns:

  • (Integer)

    This player’s seat. This is a 0 indexed number that represents the order that this player joined the dealer.



34
35
36
# File 'lib/acpc_poker_types/player.rb', line 34

def seat
  @seat
end

Class Method Details

.create_players(player_names, game_def) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/acpc_poker_types/player.rb', line 12

def self.create_players(player_names, game_def)
  if game_def.number_of_players != player_names.length
    raise(
      IncorrectNumberOfPlayerNames,
      "#{player_names.length} names for #{game_def.number_of_players} players"
    )
  end

  game_def.number_of_players.times.inject([]) do |players, seat|
    players << AcpcPokerTypes::Player.join_match(
      player_names[seat],
      seat,
      AcpcPokerTypes::ChipStack.new(game_def.chip_stacks[seat])
    )
  end
end

Instance Method Details

#==(other) ⇒ Object



73
74
75
76
# File 'lib/acpc_poker_types/player.rb', line 73

def ==(other)
  equal_on_public_info?(other) &&
  @hole_cards == other.hole_cards
end

#active?Boolean

Returns Whether or not this player is active (has not folded or gone all-in). true if this player is active, false otherwise.

Returns:

  • (Boolean)

    Whether or not this player is active (has not folded or gone all-in). true if this player is active, false otherwise.



132
133
134
# File 'lib/acpc_poker_types/player.rb', line 132

def active?
  !(folded? || all_in?)
end

#all_in?Boolean

Returns Reports whether or not this player is all-in.

Returns:

  • (Boolean)

    Reports whether or not this player is all-in.



126
127
128
# File 'lib/acpc_poker_types/player.rb', line 126

def all_in?
  0 == @chip_stack
end

#assign_cards!(hole_cards) ⇒ Object



149
150
151
152
153
# File 'lib/acpc_poker_types/player.rb', line 149

def assign_cards!(hole_cards)
  @hole_cards = hole_cards

  self
end

#equal_on_public_info?(other) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
# File 'lib/acpc_poker_types/player.rb', line 78

def equal_on_public_info?(other)
  @name == other.name &&
  @seat == other.seat &&
  @chip_stack == other.chip_stack &&
  @chip_contributions == other.chip_contributions &&
  @chip_balance == other.chip_balance &&
  @actions_taken_this_hand == other.actions_taken_this_hand
end

#folded?Boolean

Returns Reports whether or not this player has folded.

Returns:

  • (Boolean)

    Reports whether or not this player has folded.



119
120
121
122
123
# File 'lib/acpc_poker_types/player.rb', line 119

def folded?
  @actions_taken_this_hand.any? do |actions|
    actions.any? { |action| action == AcpcPokerTypes::PokerAction::FOLD }
  end
end

#roundInteger

Returns The current round, zero indexed.

Returns:

  • (Integer)

    The current round, zero indexed.



137
138
139
# File 'lib/acpc_poker_types/player.rb', line 137

def round
  @actions_taken_this_hand.length - 1
end

#start_new_hand!(blind = AcpcPokerTypes::ChipStack.new(0), chip_stack = @chip_stack, hole_cards = AcpcPokerTypes::Hand.new) ⇒ Object

Parameters:

  • blind_amount (#to_i)

    The blind amount for this player to pay.

  • chip_stack (#to_i) (defaults to: @chip_stack)

    (see #chip_stack)

  • hole_cards (Hand) (defaults to: AcpcPokerTypes::Hand.new)

    (see #hole_cards)



90
91
92
93
94
95
96
97
98
99
# File 'lib/acpc_poker_types/player.rb', line 90

def start_new_hand!(blind=AcpcPokerTypes::ChipStack.new(0), chip_stack=@chip_stack, hole_cards=AcpcPokerTypes::Hand.new)
  @chip_stack = chip_stack
  @hole_cards = hole_cards
  @actions_taken_this_hand = []
  @chip_contributions = []

  start_new_round!

  pay_blind! blind
end

#start_new_round!Object



101
102
103
104
105
106
# File 'lib/acpc_poker_types/player.rb', line 101

def start_new_round!
  @actions_taken_this_hand << []
  @chip_contributions << 0

  self
end

#take_action!(action, pot_gained_chips: true, sees_wager: pot_gained_chips) ⇒ Object

Parameters:

  • action (PokerAction)

    The action to take.

  • pot_gained_chips (Boolean) (defaults to: true)

    Whether or not the pot had gained chips before this action. Defaults to true.

  • sees_wager (Boolean) (defaults to: pot_gained_chips)

    Whether or not the player is reacting to a wager. Defaults to the value of pot_gained_chips.



112
113
114
115
116
# File 'lib/acpc_poker_types/player.rb', line 112

def take_action!(action, pot_gained_chips: true, sees_wager: pot_gained_chips)
  @actions_taken_this_hand.last << action.to_s(pot_gained_chips: pot_gained_chips, player_sees_wager: sees_wager)

  take_from_chip_stack! action.cost.to_r
end

#take_winnings!(chips) ⇒ Object

Adjusts this player’s state when it takes chips from the pot.

Parameters:

  • chips (Integer)

    The number of chips this player has won from the pot.



143
144
145
146
147
# File 'lib/acpc_poker_types/player.rb', line 143

def take_winnings!(chips)
  @chip_contributions << 0

  add_to_stack! chips
end