Module: AcpcPokerTypes::SeatLike
- Included in:
- Seat
- Defined in:
- lib/acpc_poker_types/seat.rb
Instance Method Summary collapse
-
#position_relative_to(seat, number_of_players) ⇒ Integer
The relative position of
self
toseat
, given the number of players at the table,number_of_players
, indexed such that the seat immediately to the left ofseat
has aposition_relative_to
of zero. -
#seat_from_relative_position(relative_position_of_self_to_result, number_of_players) ⇒ Integer
Inverse operation of
position_relative_to
. -
#seat_in_bounds?(number_of_players) ⇒ Bool
Reports whether or not
self
represents an out of bounds seat.
Instance Method Details
#position_relative_to(seat, number_of_players) ⇒ Integer
Returns The relative position of self
to seat
, given the number of players at the table, number_of_players
, indexed such that the seat immediately to the left of seat
has a position_relative_to
of zero.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/acpc_poker_types/seat.rb', line 13 def position_relative_to(seat, number_of_players) unless seat.seat_in_bounds?(number_of_players) && seat_in_bounds?(number_of_players) raise "Seat #{seat} out of bounds for #{number_of_players} players" end adjusted_seat = if self > seat self else self + number_of_players end adjusted_seat - seat - 1 end |
#seat_from_relative_position(relative_position_of_self_to_result, number_of_players) ⇒ Integer
Inverse operation of position_relative_to
. Given
<code>relative_position = seat.position_relative_to to_seat, number_of_players</code>
then
<code>to_seat = seat.seat_from_relative_position relative_position, number_of_players</code>
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/acpc_poker_types/seat.rb', line 43 def seat_from_relative_position( relative_position_of_self_to_result, number_of_players ) unless seat_in_bounds?(number_of_players) raise "Seat #{seat} out of bounds for #{number_of_players} players" end unless relative_position_of_self_to_result.seat_in_bounds?( number_of_players ) raise "Relative position #{relative_position_of_self_to_result} out of bounds for #{number_of_players} players" end position_adjustment = relative_position_of_self_to_result + 1 to_seat = self.class.new( self + number_of_players - position_adjustment ) if self > to_seat || !to_seat.seat_in_bounds?(number_of_players) self - position_adjustment else to_seat end end |
#seat_in_bounds?(number_of_players) ⇒ Bool
Returns Reports whether or not self
represents an out of bounds seat.
72 73 74 |
# File 'lib/acpc_poker_types/seat.rb', line 72 def seat_in_bounds?(number_of_players) self < number_of_players && self >= 0 end |