Class: Table
- Inherits:
-
Object
- Object
- Table
- Defined in:
- lib/rora/model/table.rb
Overview
A poker table where players compete for pots.
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#deck ⇒ Object
readonly
Returns the value of attribute deck.
-
#pot ⇒ Object
readonly
Returns the value of attribute pot.
Instance Method Summary collapse
- #add(player, seat_number = nil) ⇒ Object
- #empty? ⇒ Boolean
- #full? ⇒ Boolean
-
#initialize(seats = nil) ⇒ Table
constructor
A new instance of Table.
- #pass_the_buck ⇒ Object
- #players ⇒ Object
- #remove(player) ⇒ Object
- #reset ⇒ Object
- #seat(i) ⇒ Object
- #size ⇒ Object
- #the_big_blind ⇒ Object
- #the_button ⇒ Object
- #the_seat_after(seat) ⇒ Object
- #the_seat_before(seat) ⇒ Object
- #the_small_blind ⇒ Object
- #under_the_gun ⇒ Object
- #with(argument) ⇒ Object
Constructor Details
#initialize(seats = nil) ⇒ Table
Returns a new instance of Table.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rora/model/table.rb', line 7 def initialize seats=nil seats = seats.nil? ? 9 : seats raise ArgumentError, "A table must have at least two seats" if seats < 2 @seats = Array.new seats @board = Board.new @pot = Pot.new @deck = Deck.new @seats.each_index {|index| @seats[index] = Seat.new(index + 1)} @seats.each_index do |index| @seats[index].next = @seats[index == (seats - 1) ? 0 : index + 1] @seats[index].prev = @seats[index == 0 ? seats - 1 : index - 1] end end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
5 6 7 |
# File 'lib/rora/model/table.rb', line 5 def board @board end |
#deck ⇒ Object (readonly)
Returns the value of attribute deck.
5 6 7 |
# File 'lib/rora/model/table.rb', line 5 def deck @deck end |
#pot ⇒ Object (readonly)
Returns the value of attribute pot.
5 6 7 |
# File 'lib/rora/model/table.rb', line 5 def pot @pot end |
Instance Method Details
#add(player, seat_number = nil) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/rora/model/table.rb', line 105 def add player, seat_number=nil raise RuntimeError, "Cannot add player, the table is full" if full? if !seat_number.nil? raise ArgumentError, "Seat number #{seat_number} does not exist at this table" if seat_number > @seats.size || seat_number < 1 raise ArgumentError, "Seat number #{seat_number} is already taken by another player" if @seats[seat_number - 1].taken? @seats[seat_number - 1].player = player return self end @seats.each_index do |x| if !@seats[x].taken? @seats[x].player = player return self end end self end |
#empty? ⇒ Boolean
101 102 103 |
# File 'lib/rora/model/table.rb', line 101 def empty? @seats.select{|x| x.taken?}.empty? end |
#full? ⇒ Boolean
97 98 99 |
# File 'lib/rora/model/table.rb', line 97 def full? @seats.select{|x| !x.taken?}.empty? end |
#pass_the_buck ⇒ Object
22 23 24 25 26 |
# File 'lib/rora/model/table.rb', line 22 def pass_the_buck index = .number - 1 @seats[index]. = nil the_seat_after(@seats[index]). = true end |
#players ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/rora/model/table.rb', line 89 def players players = [] @seats.each do |seat| players << seat.player if seat.taken? end players end |
#remove(player) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/rora/model/table.rb', line 122 def remove player @seats.each_index do |x| if @seats[x].player == player @seats[x].player = nil end end end |
#reset ⇒ Object
83 84 85 86 87 |
# File 'lib/rora/model/table.rb', line 83 def reset @board = Board.new @pot = Pot.new @deck = Deck.new end |
#seat(i) ⇒ Object
75 76 77 |
# File 'lib/rora/model/table.rb', line 75 def seat i @seats[i - 1] end |
#size ⇒ Object
79 80 81 |
# File 'lib/rora/model/table.rb', line 79 def size @seats.size end |
#the_big_blind ⇒ Object
42 43 44 |
# File 'lib/rora/model/table.rb', line 42 def the_big_blind the_seat_after the_small_blind end |
#the_button ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/rora/model/table.rb', line 28 def raise RuntimeError, "There are fewer than two players at the table" if players.size < 2 @seats.each_index do |x| return @seats[x] if @seats[x]. end @seats.each_index do |x| return @seats[x] if @seats[x].taken? end end |
#the_seat_after(seat) ⇒ Object
50 51 52 53 54 |
# File 'lib/rora/model/table.rb', line 50 def the_seat_after seat raise RuntimeError, "There are fewer than two players at the table" if players.size < 2 this_seat = seat.next return this_seat.taken? ? this_seat : the_seat_after(this_seat) end |
#the_seat_before(seat) ⇒ Object
56 57 58 59 60 |
# File 'lib/rora/model/table.rb', line 56 def the_seat_before seat raise RuntimeError, "There are fewer than two players at the table" if players.size < 2 this_seat = seat.prev return this_seat.taken? ? this_seat : the_seat_before(this_seat) end |
#the_small_blind ⇒ Object
38 39 40 |
# File 'lib/rora/model/table.rb', line 38 def the_small_blind players.size == 2 ? : the_seat_after() end |
#under_the_gun ⇒ Object
46 47 48 |
# File 'lib/rora/model/table.rb', line 46 def under_the_gun the_seat_after(the_big_blind) end |