Class: Holdem::Player
- Inherits:
-
Object
- Object
- Holdem::Player
- Defined in:
- lib/player.rb
Constant Summary collapse
- MAX_ACTIONS =
300
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#delta ⇒ Object
readonly
Returns the value of attribute delta.
-
#folded ⇒ Object
readonly
Returns the value of attribute folded.
-
#hand ⇒ Object
readonly
Returns the value of attribute hand.
-
#hole_cards ⇒ Object
readonly
Returns the value of attribute hole_cards.
-
#in_pot ⇒ Object
readonly
Returns the value of attribute in_pot.
-
#in_round ⇒ Object
readonly
Returns the value of attribute in_round.
Instance Method Summary collapse
-
#act(game) ⇒ Object
override this for subclass Players.
- #award(amount) ⇒ Object
- #deal(card) ⇒ Object
- #find_hand(board) ⇒ Object
- #fold ⇒ Object
-
#initialize ⇒ Player
constructor
A new instance of Player.
- #next_round ⇒ Object
- #pay(amount) ⇒ Object
- #record_action(action) ⇒ Object
Constructor Details
#initialize ⇒ Player
Returns a new instance of Player.
9 10 11 12 13 14 15 16 |
# File 'lib/player.rb', line 9 def initialize @hole_cards = [] @actions = [] @in_pot = 0.0 @in_round = 0.0 @delta = 0.0 @folded = false end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
7 8 9 |
# File 'lib/player.rb', line 7 def actions @actions end |
#delta ⇒ Object (readonly)
Returns the value of attribute delta.
7 8 9 |
# File 'lib/player.rb', line 7 def delta @delta end |
#folded ⇒ Object (readonly)
Returns the value of attribute folded.
7 8 9 |
# File 'lib/player.rb', line 7 def folded @folded end |
#hand ⇒ Object (readonly)
Returns the value of attribute hand.
7 8 9 |
# File 'lib/player.rb', line 7 def hand @hand end |
#hole_cards ⇒ Object (readonly)
Returns the value of attribute hole_cards.
7 8 9 |
# File 'lib/player.rb', line 7 def hole_cards @hole_cards end |
#in_pot ⇒ Object (readonly)
Returns the value of attribute in_pot.
7 8 9 |
# File 'lib/player.rb', line 7 def in_pot @in_pot end |
#in_round ⇒ Object (readonly)
Returns the value of attribute in_round.
7 8 9 |
# File 'lib/player.rb', line 7 def in_round @in_round end |
Instance Method Details
#act(game) ⇒ Object
override this for subclass Players
39 40 41 |
# File 'lib/player.rb', line 39 def act(game) return :neutral end |
#award(amount) ⇒ Object
34 35 36 |
# File 'lib/player.rb', line 34 def award(amount) @delta += amount end |
#deal(card) ⇒ Object
18 19 20 21 |
# File 'lib/player.rb', line 18 def deal(card) raise "Player already has 2 hole cards" if @hole_cards.length >= 2 @hole_cards << card end |
#find_hand(board) ⇒ Object
23 24 25 26 |
# File 'lib/player.rb', line 23 def find_hand(board) all_cards = (board + @hole_cards).flatten @hand = Hand.new(all_cards) end |
#fold ⇒ Object
52 53 54 |
# File 'lib/player.rb', line 52 def fold @folded = true end |
#next_round ⇒ Object
48 49 50 |
# File 'lib/player.rb', line 48 def next_round @in_round = 0.0 end |
#pay(amount) ⇒ Object
28 29 30 31 32 |
# File 'lib/player.rb', line 28 def pay(amount) @in_pot += amount @in_round += amount @delta -= amount end |
#record_action(action) ⇒ Object
43 44 45 46 |
# File 'lib/player.rb', line 43 def record_action(action) @actions << action @actions.delete_at(0) if @actions.length > MAX_ACTIONS end |