Class: AcpcPokerTypes::Player
- Inherits:
-
Object
- Object
- AcpcPokerTypes::Player
- Defined in:
- lib/acpc_poker_types/player.rb
Instance Attribute Summary collapse
-
#actions_taken_this_hand ⇒ Array<Array<String>>
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<AcpcPokerTypes::ChipStack>
readonly
This player’s contribution to the pot in the current hand, organized by round.
-
#chip_stack ⇒ AcpcPokerTypes::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 = AcpcPokerTypes::ChipStack.new(0), chip_stack = @chip_stack, hole_cards = AcpcPokerTypes::Hand.new) ⇒ Object
- #start_new_round! ⇒ Object
- #take_action!(action, pot_gained_chips: true, sees_wager: pot_gained_chips) ⇒ 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.
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_hand ⇒ Array<Array<String>> (readonly)
Returns 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_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.
46 47 48 |
# File 'lib/acpc_poker_types/player.rb', line 46 def chip_balance @chip_balance end |
#chip_contributions ⇒ Array<AcpcPokerTypes::ChipStack> (readonly)
Returns This player’s contribution to the pot in the current hand, organized by round.
41 42 43 |
# File 'lib/acpc_poker_types/player.rb', line 41 def chip_contributions @chip_contributions end |
#chip_stack ⇒ AcpcPokerTypes::ChipStack (readonly)
Returns This player’s chip stack.
37 38 39 |
# File 'lib/acpc_poker_types/player.rb', line 37 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.
51 52 53 |
# File 'lib/acpc_poker_types/player.rb', line 51 def hole_cards @hole_cards end |
#name ⇒ String (readonly)
Returns The name of this player.
30 31 32 |
# File 'lib/acpc_poker_types/player.rb', line 30 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.
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.
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.
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
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.
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 |
#round ⇒ Integer
Returns 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
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
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.
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 |