Class: Player

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

Overview

A player in a Texas Hold’em game.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, stack) ⇒ Player

Returns a new instance of Player.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
# File 'lib/rora/model/player.rb', line 7

def initialize name, stack
  raise ArgumentError, "The player name cannot be nil" if name.nil?
  @name = name
  @stack = stack.nil? ? 0 : stack
  @sitting_out = true
  @table = nil
  @cards = []
  @log = GameLogger.new
end

Instance Attribute Details

#gameObject (readonly)

Returns the value of attribute game.



5
6
7
# File 'lib/rora/model/player.rb', line 5

def game
  @game
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rora/model/player.rb', line 5

def name
  @name
end

#stackObject (readonly)

Returns the value of attribute stack.



5
6
7
# File 'lib/rora/model/player.rb', line 5

def stack
  @stack
end

Instance Method Details

#actObject



60
61
62
63
64
# File 'lib/rora/model/player.rb', line 60

def act
  raise_error_if_sitting_out "cannot act"
  action = "folds"
  @log.info("#{name} #{action}")
end

#add(card) ⇒ Object



42
43
44
# File 'lib/rora/model/player.rb', line 42

def add card
  @cards << card
end

#end_sessionObject



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

def end_session
  @sitting_out = true
end

#join_game(game, seat = nil) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
# File 'lib/rora/model/player.rb', line 17

def join_game game, seat=nil
  raise ArgumentError, "#{@name} cannot join this game, the table is full" if game.table.full?
  raise ArgumentError, "#{@name} cannot join this game, this player is already playing another game" if !@game.nil?
  game.table.add self, seat
  @game = game
end

#leave_gameObject



24
25
26
27
# File 'lib/rora/model/player.rb', line 24

def leave_game
  end_session
  @game = nil
end

#post_big_blindObject



55
56
57
58
# File 'lib/rora/model/player.rb', line 55

def post_big_blind
  raise_error_if_sitting_out "cannot post the big blind"
  @game.place_bet @game.buy_in / 100.00
end

#post_small_blindObject



50
51
52
53
# File 'lib/rora/model/player.rb', line 50

def post_small_blind
  raise_error_if_sitting_out "cannot post the small blind"
  @game.place_bet @game.buy_in / 200.00
end

#sitting_out?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rora/model/player.rb', line 38

def sitting_out?
  @sitting_out
end

#start_sessionObject

Raises:

  • (ArgumentError)


29
30
31
32
# File 'lib/rora/model/player.rb', line 29

def start_session
  raise ArgumentError, "#{@name} is not sitting at a table" if @game.nil?
  @sitting_out = false
end

#starting_handObject



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

def starting_hand
  StartingHand.new(@cards)
end