acpc_poker_basic_proxy 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/acpc_poker_basic_proxy.gemspec +0 -1
- data/lib/acpc_poker_basic_proxy/basic_proxy.rb +25 -8
- data/lib/acpc_poker_basic_proxy/dealer_stream.rb +3 -1
- data/lib/acpc_poker_basic_proxy/version.rb +1 -1
- data/spec/basic_proxy_spec.rb +77 -33
- data/spec/support/spec_helper.rb +1 -3
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d6dff95db6eef3d31825a87fc46bf7aec6090c5
|
4
|
+
data.tar.gz: 4a80071d3e101764f00c8e0a1812881825a09d3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04bd293fcb8daa161acd57ee2250596ea934dc604db45440f06a2e03ddfdc3b823311d61b1ffae02aeaaa5637106693792f62c659b9d2e406795955d6cf90d9d
|
7
|
+
data.tar.gz: 432b48c811b643e16dc13aec3fe674ff556837a833c5cd265f615e9546d71f002b8fe89dc2ecfb7b6b028dbf01773b2222b844d1d3d788e2d4c85df8a0841581
|
@@ -20,7 +20,6 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
22
|
s.add_development_dependency 'minitest', '~> 4.7'
|
23
|
-
s.add_development_dependency 'mocha', '~> 0.13'
|
24
23
|
s.add_development_dependency 'awesome_print', '~> 1.0'
|
25
24
|
s.add_development_dependency 'pry-rescue', '~> 1.0'
|
26
25
|
s.add_development_dependency 'simplecov', '~> 0.7'
|
@@ -11,12 +11,14 @@ module AcpcPokerBasicProxy
|
|
11
11
|
class BasicProxy
|
12
12
|
exceptions :initial_match_state_not_yet_received, :illegal_action_format
|
13
13
|
|
14
|
-
CONCATENATED_MODIFIABLE_ACTIONS =
|
14
|
+
CONCATENATED_MODIFIABLE_ACTIONS = (
|
15
|
+
AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.to_a.join
|
16
|
+
)
|
15
17
|
|
16
18
|
# Sends the given +action+ to through the given +connection+ in the ACPC
|
17
19
|
# format.
|
18
|
-
# @param [#write, #ready_to_write?] connection The connection through
|
19
|
-
#
|
20
|
+
# @param [#write, #ready_to_write?] connection The connection through
|
21
|
+
# which the +action+ should send.
|
20
22
|
# @param [#to_s] match_state The current match state.
|
21
23
|
# @param [#to_s] action The action to send through the +connection+.
|
22
24
|
# @return [Integer] The number of bytes written.
|
@@ -25,17 +27,27 @@ module AcpcPokerBasicProxy
|
|
25
27
|
def self.send_action(connection, match_state, action)
|
26
28
|
validate_action action
|
27
29
|
|
28
|
-
full_action =
|
30
|
+
full_action = (
|
31
|
+
"#{AcpcPokerTypes::MatchState.parse(match_state.to_s)}:#{action.to_s}"
|
32
|
+
)
|
29
33
|
connection.write full_action
|
30
34
|
end
|
31
35
|
|
32
36
|
# Sends a comment the given +connection+.
|
33
|
-
# @param [#write, #ready_to_write?] connection The connection through
|
34
|
-
#
|
37
|
+
# @param [#write, #ready_to_write?] connection The connection through
|
38
|
+
# which the +comment+ should send.
|
35
39
|
# @param [#to_s] comment The comment to send through the +connection+.
|
36
40
|
# @return [Integer] The number of bytes written.
|
37
41
|
def self.send_comment(connection, comment)
|
38
|
-
connection.write comment
|
42
|
+
connection.write "##{comment}"
|
43
|
+
end
|
44
|
+
|
45
|
+
# Sends a ready message to the given +connection+.
|
46
|
+
# @param [#write, #ready_to_write?] connection The connection through
|
47
|
+
# which the message should send.
|
48
|
+
# @return [Integer] The number of bytes written.
|
49
|
+
def self.send_ready(connection)
|
50
|
+
connection.write DealerStream::READY_MESSAGE
|
39
51
|
end
|
40
52
|
|
41
53
|
# @raise IllegalActionFormat
|
@@ -66,11 +78,16 @@ module AcpcPokerBasicProxy
|
|
66
78
|
end
|
67
79
|
|
68
80
|
# @param [#to_s] comment The comment to send.
|
69
|
-
# @return (see BasicProxy#
|
81
|
+
# @return (see BasicProxy#send_comment)
|
70
82
|
def send_comment(comment)
|
71
83
|
BasicProxy.send_comment @dealer_communicator, comment
|
72
84
|
end
|
73
85
|
|
86
|
+
# @return (see BasicProxy#send_ready)
|
87
|
+
def send_ready
|
88
|
+
BasicProxy.send_ready @dealer_communicator
|
89
|
+
end
|
90
|
+
|
74
91
|
# @see MatchStateReceiver#receive_match_state
|
75
92
|
def receive_match_state!
|
76
93
|
@match_state = AcpcPokerTypes::MatchState.receive @dealer_communicator
|
@@ -57,6 +57,8 @@ module AcpcPokerBasicProxy
|
|
57
57
|
# @return [String] Dealer specified string terminator.
|
58
58
|
TERMINATION_STRING = "\r\n"
|
59
59
|
|
60
|
+
READY_MESSAGE = '#READY'
|
61
|
+
|
60
62
|
# @param [Integer] port The port on which to connect to the dealer.
|
61
63
|
# @param [String] host_name The host on which the dealer is running. Defaults to 'localhost'
|
62
64
|
# @raise AcpcDealerConnectionError, UnableToWriteToDealer
|
@@ -136,4 +138,4 @@ module AcpcPokerBasicProxy
|
|
136
138
|
@dealer_socket.gets.chomp
|
137
139
|
end
|
138
140
|
end
|
139
|
-
end
|
141
|
+
end
|
data/spec/basic_proxy_spec.rb
CHANGED
@@ -13,19 +13,27 @@ include AcpcPokerTypes
|
|
13
13
|
include DealerData
|
14
14
|
|
15
15
|
describe BasicProxy do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
DealerStream.expects(:new).once.with(port_number, host_name).returns(@dealer_communicator)
|
16
|
+
let(:port_number) { 9001 }
|
17
|
+
let(:host_name) { 'localhost' }
|
18
|
+
let(:millisecond_response_timeout) { 0 }
|
19
|
+
let(:delaer_info) do
|
20
|
+
AcpcDealer::ConnectionInformation.new port_number, host_name
|
21
|
+
end
|
22
|
+
let(:dealer_communicator) { MiniTest::Mock.new 'DealerStream' }
|
24
23
|
|
25
|
-
|
24
|
+
let(:patient) do
|
25
|
+
fussy = ->(port, host) do
|
26
|
+
host.must_equal host_name
|
27
|
+
port.must_equal port_number
|
28
|
+
dealer_communicator
|
29
|
+
end
|
30
|
+
DealerStream.stub :new, fussy do
|
31
|
+
BasicProxy.new delaer_info
|
32
|
+
end
|
33
|
+
end
|
26
34
|
|
27
|
-
|
28
|
-
|
35
|
+
let(:match_state) do
|
36
|
+
PokerMatchData.parse_files(
|
29
37
|
MatchLog.all[0].actions_file_path,
|
30
38
|
MatchLog.all[0].results_file_path,
|
31
39
|
MatchLog.all[0].player_names,
|
@@ -53,55 +61,91 @@ describe BasicProxy do
|
|
53
61
|
end
|
54
62
|
match_state = match.current_hand.current_match_state
|
55
63
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
if action && match_state == match.current_hand.next_action.state && match.current_hand.next_action.seat == seat
|
61
|
-
|
62
|
-
BasicProxy.expects(:send_action).once.with(@dealer_communicator, match_state.to_s, action)
|
64
|
+
dealer_communicator.stub :gets, match_state.to_s do
|
65
|
+
patient.receive_match_state!.must_equal match_state
|
66
|
+
end
|
63
67
|
|
64
|
-
|
68
|
+
if (
|
69
|
+
action &&
|
70
|
+
match_state == match.current_hand.next_action.state &&
|
71
|
+
match.current_hand.next_action.seat == seat
|
72
|
+
)
|
73
|
+
fussy = ->(dealer_communicator_, match_state_, action_) do
|
74
|
+
dealer_communicator_.must_equal dealer_communicator
|
75
|
+
match_state_.must_equal match_state.to_s
|
76
|
+
action_.must_equal action
|
77
|
+
end
|
78
|
+
BasicProxy.stub :send_action, fussy do
|
79
|
+
patient.send_action(action)
|
80
|
+
end
|
65
81
|
end
|
66
82
|
end
|
67
83
|
end
|
68
84
|
end
|
69
85
|
end
|
70
86
|
end
|
87
|
+
describe '::send_comment' do
|
88
|
+
it 'works' do
|
89
|
+
comment = 'this is a comment'
|
90
|
+
dealer_communicator.expect :write, nil, ["##{comment}"]
|
91
|
+
BasicProxy.send_comment(dealer_communicator, comment)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
describe '::send_ready' do
|
95
|
+
it 'works' do
|
96
|
+
dealer_communicator.expect :write, nil, [DealerStream::READY_MESSAGE]
|
97
|
+
BasicProxy.send_ready(dealer_communicator)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
describe '#send_comment' do
|
101
|
+
it 'works' do
|
102
|
+
comment = 'this is a comment'
|
103
|
+
dealer_communicator.expect :write, nil, ["##{comment}"]
|
104
|
+
patient.send_comment(comment)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
describe '#send_ready' do
|
108
|
+
it 'works' do
|
109
|
+
dealer_communicator.expect :write, nil, [DealerStream::READY_MESSAGE]
|
110
|
+
patient.send_ready
|
111
|
+
end
|
112
|
+
end
|
71
113
|
describe '#send_action' do
|
72
114
|
it 'raises an exception if a match state was not received before an action was sent' do
|
73
|
-
-> {
|
115
|
+
-> {patient.send_action(MiniTest::Mock.new('PokerAction'))}.must_raise(
|
116
|
+
BasicProxy::InitialMatchStateNotYetReceived
|
117
|
+
)
|
74
118
|
end
|
75
119
|
end
|
76
|
-
describe "
|
120
|
+
describe "::send_action" do
|
77
121
|
it 'does not send an illegal action and raises an exception' do
|
78
122
|
-> do
|
79
|
-
BasicProxy.send_action(
|
123
|
+
BasicProxy.send_action(dealer_communicator, match_state, 'illegal action format')
|
80
124
|
end.must_raise BasicProxy::IllegalActionFormat
|
81
125
|
end
|
82
|
-
it 'can send all legal actions through the provided
|
126
|
+
it 'can send all legal actions through the provided dealer_communicator without a modifier' do
|
83
127
|
PokerAction::ACTIONS.each do |action|
|
84
|
-
action_that_should_be_sent =
|
85
|
-
|
128
|
+
action_that_should_be_sent = match_state.to_s + ":#{action}"
|
129
|
+
dealer_communicator.expect :write, nil, [action_that_should_be_sent]
|
86
130
|
|
87
|
-
BasicProxy.send_action
|
131
|
+
BasicProxy.send_action dealer_communicator, match_state, action
|
88
132
|
end
|
89
133
|
end
|
90
134
|
it 'does not send legal unmodifiable actions that have a modifier and raises an exception' do
|
91
135
|
(PokerAction::ACTIONS - PokerAction::MODIFIABLE_ACTIONS).each do |unmodifiable_action|
|
92
136
|
-> do
|
93
|
-
BasicProxy.send_action(
|
137
|
+
BasicProxy.send_action(dealer_communicator, match_state, unmodifiable_action + 9001.to_s)
|
94
138
|
end.must_raise BasicProxy::IllegalActionFormat
|
95
139
|
end
|
96
140
|
end
|
97
|
-
it 'can send all legal modifiable actions through the provided
|
141
|
+
it 'can send all legal modifiable actions through the provided dealer_communicator with a modifier' do
|
98
142
|
PokerAction::MODIFIABLE_ACTIONS.each do |action|
|
99
143
|
arbitrary_modifier = 9001
|
100
144
|
action_string = action + arbitrary_modifier.to_s
|
101
|
-
action_that_should_be_sent =
|
102
|
-
|
145
|
+
action_that_should_be_sent = match_state.to_s + ":#{action_string}"
|
146
|
+
dealer_communicator.expect :write, nil, [action_that_should_be_sent]
|
103
147
|
|
104
|
-
BasicProxy.send_action
|
148
|
+
BasicProxy.send_action dealer_communicator, match_state, action_string
|
105
149
|
end
|
106
150
|
end
|
107
151
|
it 'works for all test data examples' do
|
@@ -124,9 +168,9 @@ describe BasicProxy do
|
|
124
168
|
|
125
169
|
action_that_should_be_sent = "#{from_player_message.to_s}:#{action.to_acpc}"
|
126
170
|
|
127
|
-
|
171
|
+
dealer_communicator.expect :write, nil, [action_that_should_be_sent]
|
128
172
|
|
129
|
-
BasicProxy.send_action
|
173
|
+
BasicProxy.send_action dealer_communicator, from_player_message, action
|
130
174
|
end
|
131
175
|
end
|
132
176
|
end
|
data/spec/support/spec_helper.rb
CHANGED
@@ -5,8 +5,6 @@ require 'minitest/autorun'
|
|
5
5
|
require 'minitest/spec'
|
6
6
|
require 'minitest/mock'
|
7
7
|
|
8
|
-
require 'mocha/setup'
|
9
|
-
|
10
8
|
begin
|
11
9
|
require 'awesome_print'
|
12
10
|
module Minitest::Assertions
|
@@ -61,4 +59,4 @@ class MatchLog
|
|
61
59
|
def results_file_path
|
62
60
|
"#{DEALER_LOG_DIRECTORY}/#{@results_file_name}"
|
63
61
|
end
|
64
|
-
end
|
62
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acpc_poker_basic_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dustin Morrill
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '4.7'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: mocha
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.13'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.13'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: awesome_print
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|