acpc_poker_types 3.3.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd7d01d757da0d73681d9036950821b146f0a259
4
- data.tar.gz: 764812a45f696ade63e20fea872e4816255eb917
3
+ metadata.gz: 7a9e6ab9e6c3c0f051e1c4fda11b8e55dc09c041
4
+ data.tar.gz: d6c1841264fa5ccef433e6ef8e0b23fcfed6ac28
5
5
  SHA512:
6
- metadata.gz: 0a44162e009b32492ef5781c034885ca8c1f72317983ff5140af5137f9a2f6f688c971d6319566a370c2135c1b686d92add6db848eedf17aeec1d18ac3301df9
7
- data.tar.gz: 898543b130efa4a932eff9073921ecec00f042127fc11d78bf589501aae5e42902259fd55976dcd1064f18e7078f916ffb91565c1d7aae7a5682a29b40a50d70
6
+ metadata.gz: 08e74a6ba4f9b9f8fe183ca8f747ee96de5439874c1c861fb6c9a78adb8d4012c52ffddbdf599ed053e8c9e129bd308c06606888b9c8253a0278a8d3039832ab
7
+ data.tar.gz: 70eedd40524b43b989434d87a5e8959a3e975efc552bccbb5ddcf8f081e6c7834db1ed1d3cbc45f22a7c7a625011dca514fc93dccb2aadf1f7de2f15f777e206
@@ -12,7 +12,6 @@ require "acpc_poker_types/rank"
12
12
  require "acpc_poker_types/suit"
13
13
  require "acpc_poker_types/acpc_dealer_data"
14
14
  require 'acpc_poker_types/seat'
15
- require 'acpc_poker_types/integer_as_seat'
16
15
 
17
16
  module AcpcPokerTypes
18
17
  end
@@ -4,8 +4,7 @@ require 'acpc_poker_types/chip_stack'
4
4
  require 'acpc_poker_types/suit'
5
5
  require 'acpc_poker_types/rank'
6
6
 
7
- require 'acpc_poker_types/integer_as_seat'
8
- using AcpcPokerTypes::IntegerAsSeat
7
+ require 'acpc_poker_types/seat'
9
8
 
10
9
  require 'contextual_exceptions'
11
10
  using ContextualExceptions::ClassRefinement
@@ -303,7 +302,7 @@ module AcpcPokerTypes
303
302
  end
304
303
 
305
304
  @number_of_rounds.times do |i|
306
- unless @first_player_positions[i].seat_in_bounds? @number_of_players
305
+ unless Seat.in_bounds?(@first_player_positions[i], @number_of_players)
307
306
  raise(
308
307
  ParseError,
309
308
  "Invalid first player #{@first_player_positions[i]} on round #{i+1}"
@@ -1,85 +1,42 @@
1
1
  require 'delegate'
2
2
 
3
3
  module AcpcPokerTypes
4
- module SeatLike
5
- # @param [Integer] seat The seat to which the relative position is desired.
6
- # @param [Integer] number_of_players The number of players at the table.
7
- # @return [Integer] The relative position of +self+ to +seat+, given the
8
- # number of players at the table, +number_of_players+, indexed such that
9
- # the seat immediately to the left of +seat+ has a +position_relative_to+ of
10
- # zero.
11
- # @example <code>1.position_relative_to 0, 3</code> == 0
12
- # @example <code>1.position_relative_to 1, 3</code> == 2
13
- def position_relative_to(seat, number_of_players)
14
- unless seat.seat_in_bounds?(number_of_players) &&
15
- seat_in_bounds?(number_of_players)
16
- raise "Seat #{seat} out of bounds for #{number_of_players} players"
17
- end
4
+ class Seat < DelegateClass(Integer)
5
+ attr_reader :seat, :table_size
18
6
 
19
- adjusted_seat = if self > seat
20
- self
21
- else
22
- self + number_of_players
23
- end
24
- adjusted_seat - seat - 1
7
+ # @return [Bool] Reports whether or not +seat+ represents an out of
8
+ # bounds seat for the number of seats, +num_seats+.
9
+ def self.in_bounds?(seat, num_seats)
10
+ seat < num_seats && seat >= 0
25
11
  end
26
12
 
27
- # Inverse operation of +position_relative_to+.
28
- # Given
29
- # <code>relative_position = seat.position_relative_to to_seat, number_of_players</code>
30
- # then
31
- # <code>to_seat = seat.seat_from_relative_position relative_position, number_of_players</code>
32
- #
33
- # @param [Integer] relative_position_of_self_to_result The relative position
34
- # of seat +self+ to the seat that is returned by this function.
35
- # @param [Integer] number_of_players The number of players at the table.
36
- # @return [Integer] The seat to which the relative position,
37
- # +relative_position_of_self_to_result+, of +self+ was derived, given the
38
- # number of players at the table, +number_of_players+, indexed such that
39
- # the seat immediately to the left of +from_seat+ has a
40
- # +position_relative_to+ of zero.
41
- # @example <code>1.seat_from_relative_position 0, 3</code> == 0
42
- # @example <code>1.seat_from_relative_position 2, 3</code> == 1
43
- def seat_from_relative_position(
44
- relative_position_of_self_to_result,
45
- number_of_players
46
- )
47
- unless seat_in_bounds?(number_of_players)
48
- raise "Seat #{seat} out of bounds for #{number_of_players} players"
49
- end
13
+ def initialize(seat, num_seats_at_table)
14
+ @seat = seat.to_i
15
+ @table_size = num_seats_at_table.to_i
50
16
 
51
- unless relative_position_of_self_to_result.seat_in_bounds?(
52
- number_of_players
53
- )
54
- raise "Relative position #{relative_position_of_self_to_result} out of bounds for #{number_of_players} players"
17
+ unless in_bounds?
18
+ raise "Seat #{@seat} out of bounds for #{num_seats_at_table} players"
55
19
  end
56
20
 
57
- position_adjustment = relative_position_of_self_to_result + 1
21
+ super @seat
22
+ end
23
+ def seats_to(other_seat_number)
24
+ other_seat = self.class.new(other_seat_number, @table_size)
58
25
 
59
- to_seat = self.class.new(
60
- self + number_of_players - position_adjustment
61
- )
62
- if self > to_seat || !to_seat.seat_in_bounds?(number_of_players)
63
- self - position_adjustment
26
+ if @seat > other_seat
27
+ other_seat + @table_size
64
28
  else
65
- to_seat
66
- end
29
+ other_seat
30
+ end - @seat
67
31
  end
68
-
69
- # @param [Integer] number_of_players The number of players at the table.
70
- # @return [Bool] Reports whether or not +self+ represents an out of bounds
71
- # seat.
72
- def seat_in_bounds?(number_of_players)
73
- self < number_of_players && self >= 0
32
+ def seats_from(other_seat_number)
33
+ Seat.new(other_seat_number, @table_size).seats_to(@seat)
74
34
  end
75
- end
76
-
77
- class Seat < DelegateClass(Integer)
78
- include SeatLike
79
-
80
- def initialize(seat)
81
- @seat = seat.to_i
82
- super @seat
35
+ def n_seats_away(n)
36
+ Seat.new((n + @seat) % @table_size, @table_size)
37
+ end
38
+ def in_bounds?
39
+ self.class.in_bounds?(@seat, @table_size)
83
40
  end
84
41
  end
85
42
  end
@@ -1,3 +1,3 @@
1
1
  module AcpcPokerTypes
2
- VERSION = '3.3.1'
2
+ VERSION = '4.0.0'
3
3
  end
@@ -14,7 +14,7 @@
14
14
  <img src="./assets/0.7.1/loading.gif" alt="loading"/>
15
15
  </div>
16
16
  <div id="wrapper" style="display:none;">
17
- <div class="timestamp">Generated <abbr class="timeago" title="2013-06-03T17:03:54-06:00">2013-06-03T17:03:54-06:00</abbr></div>
17
+ <div class="timestamp">Generated <abbr class="timeago" title="2013-06-05T14:17:27-06:00">2013-06-05T14:17:27-06:00</abbr></div>
18
18
  <ul class="group_tabs"></ul>
19
19
 
20
20
  <div id="content">
data/spec/seat_spec.rb CHANGED
@@ -5,59 +5,36 @@ require "acpc_poker_types/seat"
5
5
  include AcpcPokerTypes
6
6
 
7
7
  describe Seat do
8
- describe '#position_relative_to' do
8
+ describe '#seats_to' do
9
9
  it 'works for basic examples' do
10
- Seat.new(1).position_relative_to(Seat.new(0), 3).must_equal 0
11
- Seat.new(1).position_relative_to(Seat.new(1), 3).must_equal 2
10
+ Seat.new(1, 3).seats_to(0).must_equal 2
11
+ Seat.new(1, 3).seats_to(1).must_equal 0
12
+ Seat.new(1, 3).seats_to(2).must_equal 1
12
13
  end
13
- it 'works for more cases' do
14
- (0..10).each do |patient|
15
- (0..10).each do |target|
16
- (1..10).each do |num_players|
17
- next if patient >= num_players || target >= num_players
18
-
19
- Seat.new(patient).position_relative_to(Seat.new(target), num_players)
20
- .must_equal(
21
- (
22
- if patient > target
23
- patient
24
- else
25
- patient + num_players
26
- end
27
- ) - (target + 1)
28
- )
29
- end
30
- end
31
- end
14
+ end
15
+ describe '#seats_from' do
16
+ it 'works for basic examples' do
17
+ Seat.new(1, 3).seats_from(0).must_equal 1
18
+ Seat.new(1, 3).seats_from(1).must_equal 0
19
+ Seat.new(1, 3).seats_from(2).must_equal 2
32
20
  end
33
21
  end
34
- describe '#seat_from_relative_position' do
22
+ describe '#n_seats_away' do
35
23
  it 'works for basic examples' do
36
- Seat.new(1).seat_from_relative_position(Seat.new(0), 3).must_equal 0
37
- Seat.new(1).seat_from_relative_position(Seat.new(2), 3).must_equal 1
24
+ Seat.new(1, 3).n_seats_away(0).must_equal 1
25
+ Seat.new(1, 3).n_seats_away(1).must_equal 2
26
+ Seat.new(1, 3).n_seats_away(2).must_equal 0
27
+ Seat.new(1, 3).n_seats_away(3).must_equal 1
28
+ Seat.new(1, 3).n_seats_away(6).must_equal 1
38
29
  end
39
- it 'works for more cases' do
40
- (0..10).each do |patient|
41
- (0..10).each do |rel_position|
42
- (1..10).each do |num_players|
43
- next if patient >= num_players || rel_position >= num_players
44
-
45
- position_adjustment = rel_position + 1
46
-
47
- to_seat = Seat.new(patient + num_players - position_adjustment)
48
- x_seat = if patient > to_seat || !to_seat.seat_in_bounds?(num_players)
49
- patient - position_adjustment
50
- else
51
- to_seat
52
- end
53
-
54
- Seat.new(patient).seat_from_relative_position(
55
- Seat.new(rel_position),
56
- num_players
57
- ).must_equal(x_seat)
58
- end
59
- end
60
- end
30
+ end
31
+ describe '::in_bounds?' do
32
+ it 'works for basic examples' do
33
+ Seat.in_bounds?(0, 3).must_equal true
34
+ Seat.in_bounds?(1, 3).must_equal true
35
+ Seat.in_bounds?(3, 3).must_equal false
36
+ Seat.in_bounds?(4, 3).must_equal false
37
+ Seat.in_bounds?(-1, 3).must_equal false
61
38
  end
62
39
  end
63
- end
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acpc_poker_types
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Morrill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-03 00:00:00.000000000 Z
11
+ date: 2013-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: process_runner
@@ -172,7 +172,6 @@ files:
172
172
  - lib/acpc_poker_types/pile_of_cards.rb
173
173
  - lib/acpc_poker_types/game_definition.rb
174
174
  - lib/acpc_poker_types/rank.rb
175
- - lib/acpc_poker_types/integer_as_seat.rb
176
175
  - lib/acpc_poker_types/suit.rb
177
176
  - lib/acpc_poker_types/chip_stack.rb
178
177
  - lib/acpc_poker_types/version.rb
@@ -1,8 +0,0 @@
1
- require 'acpc_poker_types/seat'
2
- module AcpcPokerTypes
3
- module IntegerAsSeat
4
- refine Integer do
5
- include SeatLike
6
- end
7
- end
8
- end