acpc_poker_types 3.2.1 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/acpc_poker_types.rb +1 -0
- data/lib/acpc_poker_types/integer_as_seat.rb +2 -66
- data/lib/acpc_poker_types/seat.rb +85 -0
- data/lib/acpc_poker_types/version.rb +1 -1
- data/spec/coverage/index.html +1 -1
- data/spec/seat_spec.rb +63 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd7d01d757da0d73681d9036950821b146f0a259
|
4
|
+
data.tar.gz: 764812a45f696ade63e20fea872e4816255eb917
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a44162e009b32492ef5781c034885ca8c1f72317983ff5140af5137f9a2f6f688c971d6319566a370c2135c1b686d92add6db848eedf17aeec1d18ac3301df9
|
7
|
+
data.tar.gz: 898543b130efa4a932eff9073921ecec00f042127fc11d78bf589501aae5e42902259fd55976dcd1064f18e7078f916ffb91565c1d7aae7a5682a29b40a50d70
|
data/lib/acpc_poker_types.rb
CHANGED
@@ -1,72 +1,8 @@
|
|
1
|
+
require 'acpc_poker_types/seat'
|
1
2
|
module AcpcPokerTypes
|
2
3
|
module IntegerAsSeat
|
3
4
|
refine Integer do
|
4
|
-
|
5
|
-
# @param [Integer] number_of_players The number of players at the table.
|
6
|
-
# @return [Integer] The relative position of +self+ to +seat+, given the
|
7
|
-
# number of players at the table, +number_of_players+, indexed such that
|
8
|
-
# the seat immediately to the left of +seat+ has a +position_relative_to+ of
|
9
|
-
# zero.
|
10
|
-
# @example <code>1.position_relative_to 0, 3</code> == 0
|
11
|
-
# @example <code>1.position_relative_to 1, 3</code> == 2
|
12
|
-
def position_relative_to(seat, number_of_players)
|
13
|
-
unless seat.seat_in_bounds?(number_of_players) &&
|
14
|
-
seat_in_bounds?(number_of_players)
|
15
|
-
raise "Seat #{seat} out of bounds for #{number_of_players} players"
|
16
|
-
end
|
17
|
-
|
18
|
-
adjusted_seat = if self > seat
|
19
|
-
self
|
20
|
-
else
|
21
|
-
self + number_of_players
|
22
|
-
end
|
23
|
-
adjusted_seat - seat - 1
|
24
|
-
end
|
25
|
-
|
26
|
-
# Inverse operation of +position_relative_to+.
|
27
|
-
# Given
|
28
|
-
# <code>relative_position = seat.position_relative_to to_seat, number_of_players</code>
|
29
|
-
# then
|
30
|
-
# <code>to_seat = seat.seat_from_relative_position relative_position, number_of_players</code>
|
31
|
-
#
|
32
|
-
# @param [Integer] relative_position_of_self_to_result The relative position
|
33
|
-
# of seat +self+ to the seat that is returned by this function.
|
34
|
-
# @param [Integer] number_of_players The number of players at the table.
|
35
|
-
# @return [Integer] The seat to which the relative position,
|
36
|
-
# +relative_position_of_self_to_result+, of +self+ was derived, given the
|
37
|
-
# number of players at the table, +number_of_players+, indexed such that
|
38
|
-
# the seat immediately to the left of +from_seat+ has a
|
39
|
-
# +position_relative_to+ of zero.
|
40
|
-
# @example <code>1.seat_from_relative_position 0, 3</code> == 0
|
41
|
-
# @example <code>1.seat_from_relative_position 2, 3</code> == 1
|
42
|
-
def seat_from_relative_position(relative_position_of_self_to_result,
|
43
|
-
number_of_players)
|
44
|
-
unless seat_in_bounds?(number_of_players)
|
45
|
-
raise "Seat #{seat} out of bounds for #{number_of_players} players"
|
46
|
-
end
|
47
|
-
|
48
|
-
unless relative_position_of_self_to_result.seat_in_bounds?(
|
49
|
-
number_of_players
|
50
|
-
)
|
51
|
-
raise "Relative position #{relative_position_of_self_to_result} out of bounds for #{number_of_players} players"
|
52
|
-
end
|
53
|
-
|
54
|
-
position_adjustment = relative_position_of_self_to_result + 1
|
55
|
-
|
56
|
-
to_seat = self + number_of_players - position_adjustment
|
57
|
-
if self > to_seat || !to_seat.seat_in_bounds?(number_of_players)
|
58
|
-
self - position_adjustment
|
59
|
-
else
|
60
|
-
to_seat
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# @param [Integer] number_of_players The number of players at the table.
|
65
|
-
# @return [Bool] Reports whether or not +self+ represents an out of bounds
|
66
|
-
# seat.
|
67
|
-
def seat_in_bounds?(number_of_players)
|
68
|
-
self < number_of_players && self >= 0
|
69
|
-
end
|
5
|
+
include SeatLike
|
70
6
|
end
|
71
7
|
end
|
72
8
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
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
|
18
|
+
|
19
|
+
adjusted_seat = if self > seat
|
20
|
+
self
|
21
|
+
else
|
22
|
+
self + number_of_players
|
23
|
+
end
|
24
|
+
adjusted_seat - seat - 1
|
25
|
+
end
|
26
|
+
|
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
|
50
|
+
|
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"
|
55
|
+
end
|
56
|
+
|
57
|
+
position_adjustment = relative_position_of_self_to_result + 1
|
58
|
+
|
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
|
64
|
+
else
|
65
|
+
to_seat
|
66
|
+
end
|
67
|
+
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
|
74
|
+
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
|
83
|
+
end
|
84
|
+
end
|
85
|
+
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-
|
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>
|
18
18
|
<ul class="group_tabs"></ul>
|
19
19
|
|
20
20
|
<div id="content">
|
data/spec/seat_spec.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Spec helper (must include first to track code coverage with SimpleCov)
|
2
|
+
require File.expand_path('../support/spec_helper', __FILE__)
|
3
|
+
|
4
|
+
require "acpc_poker_types/seat"
|
5
|
+
include AcpcPokerTypes
|
6
|
+
|
7
|
+
describe Seat do
|
8
|
+
describe '#position_relative_to' do
|
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
|
12
|
+
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
|
32
|
+
end
|
33
|
+
end
|
34
|
+
describe '#seat_from_relative_position' do
|
35
|
+
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
|
38
|
+
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
|
61
|
+
end
|
62
|
+
end
|
63
|
+
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.
|
4
|
+
version: 3.3.1
|
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-
|
11
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: process_runner
|
@@ -176,6 +176,7 @@ files:
|
|
176
176
|
- lib/acpc_poker_types/suit.rb
|
177
177
|
- lib/acpc_poker_types/chip_stack.rb
|
178
178
|
- lib/acpc_poker_types/version.rb
|
179
|
+
- lib/acpc_poker_types/seat.rb
|
179
180
|
- lib/acpc_poker_types/card.rb
|
180
181
|
- lib/acpc_poker_types/poker_action.rb
|
181
182
|
- lib/acpc_poker_types/player.rb
|
@@ -185,6 +186,7 @@ files:
|
|
185
186
|
- spec/poker_action_spec.rb
|
186
187
|
- spec/match_state_spec.rb
|
187
188
|
- spec/poker_match_data_spec.rb
|
189
|
+
- spec/seat_spec.rb
|
188
190
|
- spec/chip_stack_spec.rb
|
189
191
|
- spec/hand_results_spec.rb
|
190
192
|
- spec/card_spec.rb
|
@@ -324,6 +326,7 @@ test_files:
|
|
324
326
|
- spec/poker_action_spec.rb
|
325
327
|
- spec/match_state_spec.rb
|
326
328
|
- spec/poker_match_data_spec.rb
|
329
|
+
- spec/seat_spec.rb
|
327
330
|
- spec/chip_stack_spec.rb
|
328
331
|
- spec/hand_results_spec.rb
|
329
332
|
- spec/card_spec.rb
|