Class: Holdem::Game
- Inherits:
-
Object
- Object
- Holdem::Game
- Defined in:
- lib/game.rb
Constant Summary collapse
- ROUNDS =
[ :preflop, :flop, :turn, :river, :showdown ]
- BET_CAP =
4
Instance Attribute Summary collapse
-
#bb ⇒ Object
readonly
Returns the value of attribute bb.
-
#bets_in_round ⇒ Object
readonly
Returns the value of attribute bets_in_round.
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#deck ⇒ Object
readonly
Returns the value of attribute deck.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
-
#pot ⇒ Object
readonly
Returns the value of attribute pot.
-
#round ⇒ Object
readonly
Returns the value of attribute round.
-
#sb ⇒ Object
readonly
Returns the value of attribute sb.
-
#winners ⇒ Object
readonly
Returns the value of attribute winners.
Instance Method Summary collapse
- #bet_size ⇒ Object
-
#initialize(small_bet, num_players = 10) ⇒ Game
constructor
A new instance of Game.
- #owed(player) ⇒ Object
- #run ⇒ Object
- #run_game ⇒ Object
- #settled?(position = -1)) ⇒ Boolean
Constructor Details
#initialize(small_bet, num_players = 10) ⇒ Game
Returns a new instance of Game.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/game.rb', line 16 def initialize(small_bet, num_players=10) raise "Cannot create a game with #{num_player.to_s} players" unless (2..11).include?(num_players) @sb = small_bet/2.0 @bb = small_bet @round = ROUNDS[0] @deck = Deck.new @pot = 0.0 @bets_in_round = 1 @winners = [] @board = [] # create players and deal hole cards @players = [] (0...num_players).each do |position| if(block_given?) @players << yield(position) else @players << Player.new end end 2.times do @players.each { |p| p.deal(@deck.deal) } end # small and big blind if(@players.length == 2) @players[1].pay(@sb) @players[0].pay(@bb) else @players[0].pay(@sb) @players[1].pay(@bb) end @pot += (@sb + @bb) end |
Instance Attribute Details
#bb ⇒ Object (readonly)
Returns the value of attribute bb.
14 15 16 |
# File 'lib/game.rb', line 14 def bb @bb end |
#bets_in_round ⇒ Object (readonly)
Returns the value of attribute bets_in_round.
14 15 16 |
# File 'lib/game.rb', line 14 def bets_in_round @bets_in_round end |
#board ⇒ Object (readonly)
Returns the value of attribute board.
14 15 16 |
# File 'lib/game.rb', line 14 def board @board end |
#deck ⇒ Object (readonly)
Returns the value of attribute deck.
14 15 16 |
# File 'lib/game.rb', line 14 def deck @deck end |
#players ⇒ Object (readonly)
Returns the value of attribute players.
14 15 16 |
# File 'lib/game.rb', line 14 def players @players end |
#pot ⇒ Object (readonly)
Returns the value of attribute pot.
14 15 16 |
# File 'lib/game.rb', line 14 def pot @pot end |
#round ⇒ Object (readonly)
Returns the value of attribute round.
14 15 16 |
# File 'lib/game.rb', line 14 def round @round end |
#sb ⇒ Object (readonly)
Returns the value of attribute sb.
14 15 16 |
# File 'lib/game.rb', line 14 def sb @sb end |
#winners ⇒ Object (readonly)
Returns the value of attribute winners.
14 15 16 |
# File 'lib/game.rb', line 14 def winners @winners end |
Instance Method Details
#bet_size ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/game.rb', line 53 def bet_size if(ROUNDS.index(@round) <= 1) @bb else 2.0*@bb end end |
#owed(player) ⇒ Object
61 62 63 64 |
# File 'lib/game.rb', line 61 def owed(player) return 0.0 if player.folded (bets_in_round.to_f*bet_size)-player.in_round end |
#run ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/game.rb', line 77 def run method('do_'+round.to_s).call() if(num_active_players == 1) @round = :showdown else @round = ROUNDS[ROUNDS.index(@round)+1] end if(@round == :showdown) do_showdown end end |
#run_game ⇒ Object
91 92 93 94 95 |
# File 'lib/game.rb', line 91 def run_game while(@round != :showdown) run end end |
#settled?(position = -1)) ⇒ Boolean
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/game.rb', line 66 def settled?(position=-1) settled = true @players.each do |p| settled = false if owed(p) > 0.0 # owed takes folding into account end # option for big blind settled = false if(position == 1 && @bets_in_round == 1 && @round == :preflop) settled end |