Class: Holdem::Player

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

Constant Summary collapse

MAX_ACTIONS =
300

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlayer

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

#actionsObject (readonly)

Returns the value of attribute actions.



7
8
9
# File 'lib/player.rb', line 7

def actions
  @actions
end

#deltaObject (readonly)

Returns the value of attribute delta.



7
8
9
# File 'lib/player.rb', line 7

def delta
  @delta
end

#foldedObject (readonly)

Returns the value of attribute folded.



7
8
9
# File 'lib/player.rb', line 7

def folded
  @folded
end

#handObject (readonly)

Returns the value of attribute hand.



7
8
9
# File 'lib/player.rb', line 7

def hand
  @hand
end

#hole_cardsObject (readonly)

Returns the value of attribute hole_cards.



7
8
9
# File 'lib/player.rb', line 7

def hole_cards
  @hole_cards
end

#in_potObject (readonly)

Returns the value of attribute in_pot.



7
8
9
# File 'lib/player.rb', line 7

def in_pot
  @in_pot
end

#in_roundObject (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

#foldObject



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

def fold
  @folded = true
end

#next_roundObject



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