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 +4 -4
- data/lib/acpc_poker_types.rb +0 -1
- data/lib/acpc_poker_types/game_definition.rb +2 -3
- data/lib/acpc_poker_types/seat.rb +26 -69
- data/lib/acpc_poker_types/version.rb +1 -1
- data/spec/coverage/index.html +1 -1
- data/spec/seat_spec.rb +25 -48
- metadata +2 -3
- data/lib/acpc_poker_types/integer_as_seat.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a9e6ab9e6c3c0f051e1c4fda11b8e55dc09c041
|
4
|
+
data.tar.gz: d6c1841264fa5ccef433e6ef8e0b23fcfed6ac28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08e74a6ba4f9b9f8fe183ca8f747ee96de5439874c1c861fb6c9a78adb8d4012c52ffddbdf599ed053e8c9e129bd308c06606888b9c8253a0278a8d3039832ab
|
7
|
+
data.tar.gz: 70eedd40524b43b989434d87a5e8959a3e975efc552bccbb5ddcf8f081e6c7834db1ed1d3cbc45f22a7c7a625011dca514fc93dccb2aadf1f7de2f15f777e206
|
data/lib/acpc_poker_types.rb
CHANGED
@@ -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/
|
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]
|
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
|
-
|
5
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
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
|
52
|
-
|
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
|
-
|
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
|
-
|
60
|
-
|
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
|
-
|
66
|
-
end
|
29
|
+
other_seat
|
30
|
+
end - @seat
|
67
31
|
end
|
68
|
-
|
69
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
data/spec/coverage/index.html
CHANGED
@@ -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-
|
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 '#
|
8
|
+
describe '#seats_to' do
|
9
9
|
it 'works for basic examples' do
|
10
|
-
Seat.new(1).
|
11
|
-
Seat.new(1).
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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 '#
|
22
|
+
describe '#n_seats_away' do
|
35
23
|
it 'works for basic examples' do
|
36
|
-
Seat.new(1).
|
37
|
-
Seat.new(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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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:
|
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-
|
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
|