Class: Player
- Inherits:
-
Object
- Object
- Player
- Defined in:
- lib/acpc_poker_types/player.rb
Overview
Class to model a player.
Instance Attribute Summary collapse
-
#actions_taken_this_hand ⇒ Array<Array<PokerAction>>
readonly
The list of actions this player has taken in the current hand, separated by round.
-
#chip_balance ⇒ Integer
readonly
The amount this player has won or lost in the current match.
-
#chip_contributions ⇒ Array<ChipStack>
readonly
This player’s contribution to the pot in the current hand, organized by round.
-
#chip_stack ⇒ ChipStack
readonly
This player’s chip stack.
-
#hole_cards ⇒ Hand
readonly
This player’s hole cards or nil if this player is not holding cards.
-
#name ⇒ String
readonly
The name of this player.
-
#seat ⇒ Integer
readonly
This player’s seat.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#active? ⇒ Boolean
Whether or not this player is active (has not folded or gone all-in).
-
#all_in? ⇒ Boolean
Reports whether or not this player is all-in.
- #assign_cards!(hole_cards) ⇒ Object
- #equal_on_public_info?(other) ⇒ Boolean
-
#folded? ⇒ Boolean
Reports whether or not this player has folded.
-
#initialize(name, seat, chip_stack) ⇒ Player
constructor
A new instance of Player.
-
#round ⇒ Integer
The current round, zero indexed.
- #start_new_hand!(blind = ChipStack.new(0), chip_stack = @chip_stack, hole_cards = Hand.new) ⇒ Object
- #start_new_round! ⇒ Object
- #take_action!(action) ⇒ Object
-
#take_winnings!(chips) ⇒ Object
Adjusts this player’s state when it takes chips from the pot.
Constructor Details
#initialize(name, seat, chip_stack) ⇒ Player
These comments don’t work as expected
Returns a new instance of Player.
61 62 63 64 65 66 67 68 69 |
# File 'lib/acpc_poker_types/player.rb', line 61 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_hand ⇒ Array<Array<PokerAction>> (readonly)
Returns The list of actions this player has taken in the current hand, separated by round.
53 54 55 |
# File 'lib/acpc_poker_types/player.rb', line 53 def actions_taken_this_hand @actions_taken_this_hand end |
#chip_balance ⇒ Integer (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.
44 45 46 |
# File 'lib/acpc_poker_types/player.rb', line 44 def chip_balance @chip_balance end |
#chip_contributions ⇒ Array<ChipStack> (readonly)
Returns This player’s contribution to the pot in the current hand, organized by round.
39 40 41 |
# File 'lib/acpc_poker_types/player.rb', line 39 def chip_contributions @chip_contributions end |
#chip_stack ⇒ ChipStack (readonly)
Returns This player’s chip stack.
35 36 37 |
# File 'lib/acpc_poker_types/player.rb', line 35 def chip_stack @chip_stack end |
#hole_cards ⇒ Hand (readonly)
Returns This player’s hole cards or nil if this player is not holding cards.
49 50 51 |
# File 'lib/acpc_poker_types/player.rb', line 49 def hole_cards @hole_cards end |
#name ⇒ String (readonly)
Returns The name of this player.
28 29 30 |
# File 'lib/acpc_poker_types/player.rb', line 28 def name @name end |
#seat ⇒ Integer (readonly)
Returns This player’s seat. This is a 0 indexed number that represents the order that this player joined the dealer.
32 33 34 |
# File 'lib/acpc_poker_types/player.rb', line 32 def seat @seat end |
Class Method Details
.create_players(player_names, game_def) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/acpc_poker_types/player.rb', line 11 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 << Player.join_match(player_names[seat], seat, ChipStack.new(game_def.chip_stacks[seat]) ) end end |
Instance Method Details
#==(other) ⇒ Object
71 72 73 74 |
# File 'lib/acpc_poker_types/player.rb', line 71 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.
129 130 131 |
# File 'lib/acpc_poker_types/player.rb', line 129 def active? !(folded? || all_in?) end |
#all_in? ⇒ Boolean
Returns Reports whether or not this player is all-in.
123 124 125 |
# File 'lib/acpc_poker_types/player.rb', line 123 def all_in? 0 == @chip_stack end |
#assign_cards!(hole_cards) ⇒ Object
146 147 148 149 150 |
# File 'lib/acpc_poker_types/player.rb', line 146 def assign_cards!(hole_cards) @hole_cards = hole_cards self end |
#equal_on_public_info?(other) ⇒ Boolean
76 77 78 79 80 81 82 83 |
# File 'lib/acpc_poker_types/player.rb', line 76 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.
114 115 116 117 118 119 120 |
# File 'lib/acpc_poker_types/player.rb', line 114 def folded? if @actions_taken_this_hand.last.empty? false else :fold == @actions_taken_this_hand.last.last.to_sym end end |
#round ⇒ Integer
Returns The current round, zero indexed.
134 135 136 |
# File 'lib/acpc_poker_types/player.rb', line 134 def round @actions_taken_this_hand.length - 1 end |
#start_new_hand!(blind = ChipStack.new(0), chip_stack = @chip_stack, hole_cards = Hand.new) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/acpc_poker_types/player.rb', line 88 def start_new_hand!(blind=ChipStack.new(0), chip_stack=@chip_stack, hole_cards=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
99 100 101 102 103 104 |
# File 'lib/acpc_poker_types/player.rb', line 99 def start_new_round! @actions_taken_this_hand << [] @chip_contributions << 0 self end |
#take_action!(action) ⇒ Object
107 108 109 110 111 |
# File 'lib/acpc_poker_types/player.rb', line 107 def take_action!(action) @actions_taken_this_hand.last << action take_from_chip_stack! action.amount_to_put_in_pot end |
#take_winnings!(chips) ⇒ Object
Adjusts this player’s state when it takes chips from the pot.
140 141 142 143 144 |
# File 'lib/acpc_poker_types/player.rb', line 140 def take_winnings!(chips) @chip_contributions << 0 add_to_stack! chips end |