acpc_poker_basic_proxy 0.0.3 → 1.0.0
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 +7 -0
- data/Rakefile +9 -29
- data/acpc_poker_basic_proxy.gemspec +13 -10
- data/lib/acpc_poker_basic_proxy.rb +2 -6
- data/lib/acpc_poker_basic_proxy/basic_proxy.rb +24 -22
- data/lib/acpc_poker_basic_proxy/communication_logic.rb +9 -0
- data/lib/acpc_poker_basic_proxy/communication_logic/acpc_dealer_communicator.rb +105 -101
- data/lib/acpc_poker_basic_proxy/communication_logic/acpc_dealer_information.rb +16 -12
- data/lib/acpc_poker_basic_proxy/communication_logic/action_sender.rb +37 -35
- data/lib/acpc_poker_basic_proxy/communication_logic/match_state_receiver.rb +12 -8
- data/lib/acpc_poker_basic_proxy/version.rb +1 -1
- data/spec/acpc_dealer_communicator_spec.rb +67 -0
- data/spec/acpc_dealer_information_spec.rb +10 -0
- data/spec/{communication_logic/action_sender_spec.rb → action_sender_spec.rb} +28 -33
- data/spec/basic_proxy_spec.rb +11 -5
- data/spec/coverage/index.html +1438 -0
- data/spec/match_state_receiver_spec.rb +38 -0
- data/spec/support/spec_helper.rb +30 -6
- metadata +170 -328
- data/spec/communication_logic/acpc_dealer_communicator_spec.rb +0 -61
- data/spec/communication_logic/acpc_dealer_information_spec.rb +0 -9
- data/spec/communication_logic/coverage/assets/0.5.3/app.js +0 -88
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +0 -363
- data/spec/communication_logic/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
- data/spec/communication_logic/coverage/assets/0.5.3/favicon_green.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/favicon_red.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/favicon_yellow.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/highlight.css +0 -129
- data/spec/communication_logic/coverage/assets/0.5.3/highlight.pack.js +0 -1
- data/spec/communication_logic/coverage/assets/0.5.3/jquery-1.6.2.min.js +0 -18
- data/spec/communication_logic/coverage/assets/0.5.3/jquery.dataTables.min.js +0 -152
- data/spec/communication_logic/coverage/assets/0.5.3/jquery.timeago.js +0 -141
- data/spec/communication_logic/coverage/assets/0.5.3/jquery.url.js +0 -174
- data/spec/communication_logic/coverage/assets/0.5.3/loading.gif +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/magnify.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/spec/communication_logic/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +0 -295
- data/spec/communication_logic/coverage/assets/0.5.3/stylesheet.css +0 -383
- data/spec/communication_logic/coverage/assets/0.7.1/application.css +0 -1110
- data/spec/communication_logic/coverage/assets/0.7.1/application.js +0 -626
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/blank.gif +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_close.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_loading.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_nav_left.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_nav_right.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_title_left.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_title_main.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_title_over.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_title_right.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancybox-x.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancybox-y.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancybox.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/favicon_green.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/favicon_red.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/favicon_yellow.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/loading.gif +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/magnify.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/spec/communication_logic/coverage/index.html +0 -72
- data/spec/communication_logic/match_state_receiver_spec.rb +0 -37
- data/tasks.rb +0 -32
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: e362ce7f2796d6a1dc1b1905e9651abf064ac4ca
|
|
4
|
+
data.tar.gz: 61a6d8823a269da8e878fc79a82c5f8a519ea6a8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c2d00ac00fdb9190c10f1bf1ecbac9a15eae3e75dc4877ad224dc5da70c89b04e73b85fb1f6e0b54f56006413fc0fa474370a609648bb223c38f6761cc7ed99f
|
|
7
|
+
data.tar.gz: e9974f98efcd84cec40a42dcb4699efb781a2470a6339e38dd0da7c2f3a4a1caf3690f388da44a4e8a55a171b461c88baf1d4b2031b4d305e9ea630cedb7e29f
|
data/Rakefile
CHANGED
|
@@ -1,32 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
require
|
|
3
|
-
require 'rspec/core/rake_task'
|
|
4
|
-
|
|
5
|
-
require File.expand_path('../lib/acpc_poker_basic_proxy/version', __FILE__)
|
|
6
|
-
require File.expand_path('../tasks', __FILE__)
|
|
7
|
-
|
|
8
|
-
include Tasks
|
|
9
|
-
|
|
10
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
11
|
-
ruby_opts = "-w"
|
|
12
|
-
end
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
require "bundler/gem_tasks"
|
|
13
3
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
end
|
|
4
|
+
require 'rake'
|
|
5
|
+
require 'rake/testtask'
|
|
17
6
|
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
Rake::TestTask.new do |t|
|
|
8
|
+
t.libs << "lib" << 'spec/support'
|
|
9
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
|
10
|
+
t.verbose = false
|
|
11
|
+
t.warning = false # pry-rescue has a lot of warnings
|
|
20
12
|
end
|
|
21
|
-
|
|
22
|
-
#desc "release gem to gemserver"
|
|
23
|
-
#task :release => [:tag, :deploy] do
|
|
24
|
-
# puts "congrats, the gem is now tagged, pushed, deployed and released! Rember to up the VERSION number"
|
|
25
|
-
#end
|
|
26
|
-
|
|
27
|
-
#task :deploy do
|
|
28
|
-
# puts "Deploying to gemserver@mygemserver.mycompany.com"
|
|
29
|
-
# system "scp my_private_gem-#{AcpcPokerType::VERSION}.gem gemserver@mygemserver.mycompany.com:gems/."
|
|
30
|
-
# puts "installing on gemserver"
|
|
31
|
-
# system "ssh gemserver@mygemserver.mycompany.com \"cd gems && gem install my_private_gem-#{AcpcPokerType::VERSION}.gem --ignore-dependencies\""
|
|
32
|
-
#end
|
|
@@ -9,19 +9,22 @@ Gem::Specification.new do |s|
|
|
|
9
9
|
s.homepage = "https://github.com/dmorrill10/acpc_poker_basic_proxy"
|
|
10
10
|
s.summary = %q{ACPC Poker Basic Proxy}
|
|
11
11
|
s.description = %q{Basic proxy to connect to the ACPC Dealer.}
|
|
12
|
-
|
|
13
|
-
s.add_dependency 'acpc_poker_types'
|
|
14
|
-
s.add_dependency 'dmorrill10-utils'
|
|
15
|
-
|
|
12
|
+
|
|
13
|
+
s.add_dependency 'acpc_poker_types', '~> 3.0'
|
|
14
|
+
s.add_dependency 'dmorrill10-utils', '~> 1.0'
|
|
15
|
+
|
|
16
16
|
s.rubyforge_project = "acpc_poker_basic_proxy"
|
|
17
17
|
|
|
18
|
-
s.files = Dir.glob("lib/**/*") + Dir.glob("ext/**/*") + %w(Rakefile acpc_poker_basic_proxy.gemspec
|
|
18
|
+
s.files = Dir.glob("lib/**/*") + Dir.glob("ext/**/*") + %w(Rakefile acpc_poker_basic_proxy.gemspec README.md)
|
|
19
19
|
s.test_files = Dir.glob "spec/**/*"
|
|
20
20
|
s.require_paths = ["lib"]
|
|
21
21
|
|
|
22
|
-
s.add_development_dependency '
|
|
23
|
-
s.add_development_dependency '
|
|
24
|
-
s.add_development_dependency '
|
|
25
|
-
s.add_development_dependency '
|
|
26
|
-
s.add_development_dependency '
|
|
22
|
+
s.add_development_dependency 'turn', '~> 0.9'
|
|
23
|
+
s.add_development_dependency 'minitest', '~> 4.7'
|
|
24
|
+
s.add_development_dependency 'mocha', '~> 0.13'
|
|
25
|
+
s.add_development_dependency 'acpc_dealer', '~> 0.0'
|
|
26
|
+
s.add_development_dependency 'awesome_print', '~> 1.0'
|
|
27
|
+
s.add_development_dependency 'pry-rescue', '~> 1.0'
|
|
28
|
+
s.add_development_dependency 'simplecov', '~> 0.7'
|
|
29
|
+
s.add_development_dependency 'acpc_dealer', '~> 0.0'
|
|
27
30
|
end
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'acpc_poker_basic_proxy/version'
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require File.expand_path("../acpc_poker_basic_proxy/communication_logic/acpc_dealer_communicator", __FILE__)
|
|
5
|
-
require File.expand_path("../acpc_poker_basic_proxy/communication_logic/acpc_dealer_information", __FILE__)
|
|
6
|
-
require File.expand_path("../acpc_poker_basic_proxy/communication_logic/match_state_receiver", __FILE__)
|
|
7
|
-
require File.expand_path("../acpc_poker_basic_proxy/communication_logic/action_sender", __FILE__)
|
|
3
|
+
require 'acpc_poker_basic_proxy/basic_proxy'
|
|
8
4
|
|
|
9
5
|
module AcpcPokerBasicProxy
|
|
10
6
|
end
|
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
|
|
2
|
-
require
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
2
|
+
require 'acpc_poker_basic_proxy/communication_logic/acpc_dealer_communicator'
|
|
3
|
+
require 'acpc_poker_basic_proxy/communication_logic/acpc_dealer_information'
|
|
4
|
+
require 'acpc_poker_basic_proxy/communication_logic/action_sender'
|
|
5
|
+
require 'acpc_poker_basic_proxy/communication_logic/match_state_receiver'
|
|
6
6
|
|
|
7
7
|
# A bot that connects to a dealer as a proxy.
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
module AcpcPokerBasicProxy
|
|
9
|
+
class BasicProxy
|
|
10
|
+
exceptions :initial_match_state_not_yet_received
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
# @param [AcpcDealerInformation] dealer_information Information about the dealer to which this bot should connect.
|
|
13
|
+
def initialize(dealer_information)
|
|
14
|
+
@dealer_communicator = CommunicationLogic::AcpcDealerCommunicator.new dealer_information.port_number, dealer_information.host_name, dealer_information.millisecond_response_timeout
|
|
15
|
+
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
# @param [PokerAction] action The action to be sent.
|
|
18
|
+
# @return (see ActionSender#send_action)
|
|
19
|
+
# @raise InitialMatchStateNotYetReceived
|
|
20
|
+
# @raise (see ActionSender#send_action)
|
|
21
|
+
def send_action(action)
|
|
22
|
+
raise InitialMatchStateNotYetReceived unless @match_state
|
|
23
|
+
CommunicationLogic::ActionSender.send_action @dealer_communicator, @match_state, action
|
|
24
|
+
end
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
# @see MatchStateReceiver#receive_match_state
|
|
27
|
+
def receive_match_state!
|
|
28
|
+
@match_state = CommunicationLogic::MatchStateReceiver.receive_match_state @dealer_communicator
|
|
29
|
+
end
|
|
28
30
|
end
|
|
29
|
-
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'acpc_poker_basic_proxy/communication_logic/acpc_dealer_communicator'
|
|
2
|
+
require 'acpc_poker_basic_proxy/communication_logic/acpc_dealer_information'
|
|
3
|
+
require 'acpc_poker_basic_proxy/communication_logic/match_state_receiver'
|
|
4
|
+
require 'acpc_poker_basic_proxy/communication_logic/action_sender'
|
|
5
|
+
|
|
6
|
+
module AcpcPokerBasicProxy
|
|
7
|
+
module CommunicationLogic
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -2,122 +2,126 @@
|
|
|
2
2
|
require 'socket'
|
|
3
3
|
require 'dmorrill10-utils/class'
|
|
4
4
|
|
|
5
|
-
require
|
|
5
|
+
require 'acpc_poker_basic_proxy/mixins/socket_with_ready_methods'
|
|
6
6
|
|
|
7
7
|
# Communication service to the ACPC Dealer.
|
|
8
8
|
# It acts solely as an abstraction of the communication protocol and
|
|
9
9
|
# implements the main Ruby communication interface through 'gets' and 'puts'
|
|
10
10
|
# methods.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
11
|
+
module AcpcPokerBasicProxy
|
|
12
|
+
module CommunicationLogic
|
|
13
|
+
class AcpcDealerCommunicator
|
|
14
|
+
exceptions :acpc_dealer_connection_error, :put_to_acpc_dealer_error, :get_from_acpc_dealer_error
|
|
15
|
+
|
|
16
|
+
# @return [String] The ACPC dealer version label.
|
|
17
|
+
VERSION_LABEL = 'VERSION'
|
|
18
|
+
|
|
19
|
+
# @return [Hash] The ACPC dealer version numbers.
|
|
20
|
+
VERSION_NUMBERS = {:major => 2, :minor => 0, :revision => 0}
|
|
21
|
+
|
|
22
|
+
# @return [String] Dealer specified string terminator.
|
|
23
|
+
TERMINATION_STRING = "\r\n"
|
|
24
|
+
|
|
25
|
+
# @param [Integer] port The port on which to connect to the dealer.
|
|
26
|
+
# @param [String] host_name The host on which the dealer is running.
|
|
27
|
+
# @param [Integer] millisecond_response_timeout The dealer's response timeout, in milleseconds.
|
|
28
|
+
# @raise AcpcDealerConnectionError, PutToAcpcDealerError
|
|
29
|
+
def initialize(port, host_name='localhost', millisecond_response_timeout=nil)
|
|
30
|
+
begin
|
|
31
|
+
@dealer_socket = TCPSocket.new(host_name, port)
|
|
32
|
+
@response_timeout_in_seconds = if millisecond_response_timeout
|
|
33
|
+
millisecond_response_timeout/(10**3)
|
|
34
|
+
else
|
|
35
|
+
nil
|
|
36
|
+
end
|
|
37
|
+
send_version_string_to_dealer
|
|
38
|
+
rescue PutToAcpcDealerError
|
|
39
|
+
raise
|
|
40
|
+
rescue
|
|
41
|
+
handle_error AcpcDealerConnectionError, "Unable to connect to the dealer on #{host_name} through port #{port}: #{$?}"
|
|
42
|
+
end
|
|
34
43
|
end
|
|
35
|
-
send_version_string_to_dealer
|
|
36
|
-
rescue PutToAcpcDealerError
|
|
37
|
-
raise
|
|
38
|
-
rescue
|
|
39
|
-
handle_error AcpcDealerConnectionError, "Unable to connect to the dealer on #{host_name} through port #{port}: #{$?}"
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
# Closes the connection to the dealer.
|
|
46
|
+
def close
|
|
47
|
+
@dealer_socket.close if @dealer_socket
|
|
48
|
+
end
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
# Retrieves a string from the dealer.
|
|
51
|
+
#
|
|
52
|
+
# @return [String] A string from the dealer.
|
|
53
|
+
# @raise GetFromAcpcDealerError
|
|
54
|
+
def gets
|
|
55
|
+
begin
|
|
56
|
+
raw_match_state = string_from_dealer
|
|
57
|
+
rescue
|
|
58
|
+
handle_error GetFromAcpcDealerError, "Unable to get a string from the dealer: #{$?}"
|
|
59
|
+
end
|
|
60
|
+
raw_match_state
|
|
61
|
+
end
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
# Sends a given +string+ to the dealer.
|
|
64
|
+
#
|
|
65
|
+
# @param [String] string The string to send.
|
|
66
|
+
# @return (see #send_string_to_dealer)
|
|
67
|
+
# @raise WriteToAcpcDealerError
|
|
68
|
+
def write(string)
|
|
69
|
+
begin
|
|
70
|
+
bytes_written = send_string_to_dealer string
|
|
71
|
+
rescue
|
|
72
|
+
handle_error GetFromAcpcDealerError, "Unable to send the string, \"#{string}\", to the dealer: #{$?}."
|
|
73
|
+
end
|
|
74
|
+
bytes_written
|
|
75
|
+
end
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
# @see TCPSocket#ready_to_write?
|
|
78
|
+
def ready_to_write?
|
|
79
|
+
@dealer_socket.ready_to_write? @response_timeout_in_seconds
|
|
80
|
+
end
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
# @see TCPSocket#ready_to_read?
|
|
83
|
+
def ready_to_read?
|
|
84
|
+
@dealer_socket.ready_to_read? @response_timeout_in_seconds
|
|
85
|
+
end
|
|
84
86
|
|
|
85
|
-
|
|
87
|
+
private
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
def handle_error(exception, message)
|
|
90
|
+
close
|
|
91
|
+
raise exception, message
|
|
92
|
+
end
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
# @return (see #send_string_to_dealer)
|
|
95
|
+
def send_version_string_to_dealer
|
|
96
|
+
version_string = "#{VERSION_LABEL}:#{VERSION_NUMBERS[:major]}.#{VERSION_NUMBERS[:minor]}.#{VERSION_NUMBERS[:revision]}"
|
|
97
|
+
begin
|
|
98
|
+
bytes_written = send_string_to_dealer version_string
|
|
99
|
+
rescue
|
|
100
|
+
handle_error PutToAcpcDealerError, "Unable to send version string, \"#{version_string}\", to the dealer"
|
|
101
|
+
end
|
|
102
|
+
bytes_written
|
|
103
|
+
end
|
|
102
104
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
# @return [Integer] The number of bytes written to the dealer.
|
|
106
|
+
def send_string_to_dealer(string)
|
|
107
|
+
raise unless ready_to_write?
|
|
108
|
+
begin
|
|
109
|
+
bytes_written = @dealer_socket.write(string + TERMINATION_STRING)
|
|
110
|
+
rescue
|
|
111
|
+
raise
|
|
112
|
+
end
|
|
113
|
+
bytes_written
|
|
114
|
+
end
|
|
113
115
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
def string_from_dealer
|
|
117
|
+
raise unless ready_to_read?
|
|
118
|
+
begin
|
|
119
|
+
string = @dealer_socket.gets.chomp
|
|
120
|
+
rescue
|
|
121
|
+
raise
|
|
122
|
+
end
|
|
123
|
+
string
|
|
124
|
+
end
|
|
120
125
|
end
|
|
121
|
-
string
|
|
122
126
|
end
|
|
123
|
-
end
|
|
127
|
+
end
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
|
|
2
2
|
# Information about a dealer instance.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
module AcpcPokerBasicProxy
|
|
4
|
+
module CommunicationLogic
|
|
5
|
+
class AcpcDealerInformation
|
|
6
|
+
# @return [String] The host name of the dealer associated with this table.
|
|
7
|
+
attr_reader :host_name
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
# @return [Integer] The port number of the dealer associated with this table.
|
|
10
|
+
attr_reader :port_number
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
# @return [Integer] The dealer's response timeout.
|
|
13
|
+
attr_reader :millisecond_response_timeout
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
def initialize(host_name, port_number, millisecond_response_timeout=nil)
|
|
16
|
+
@host_name = host_name
|
|
17
|
+
@port_number = port_number
|
|
18
|
+
@millisecond_response_timeout = millisecond_response_timeout
|
|
19
|
+
end
|
|
20
|
+
end
|
|
17
21
|
end
|
|
18
|
-
end
|
|
22
|
+
end
|
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
|
|
2
2
|
require 'dmorrill10-utils/class'
|
|
3
3
|
require 'acpc_poker_types/poker_action'
|
|
4
|
-
require 'acpc_poker_types/
|
|
5
|
-
require 'acpc_poker_types/suit'
|
|
4
|
+
require 'acpc_poker_types/match_state'
|
|
6
5
|
|
|
7
6
|
# Sends poker actions according to the ACPC protocol.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
module AcpcPokerBasicProxy
|
|
8
|
+
module CommunicationLogic
|
|
9
|
+
class ActionSender
|
|
10
|
+
exceptions :illegal_action_format
|
|
11
|
+
|
|
12
|
+
CONCATENATED_MODIFIABLE_ACTIONS = AcpcPokerTypes::PokerAction::MODIFIABLE_ACTIONS.to_a.join
|
|
13
|
+
|
|
14
|
+
# Sends the given +action+ to through the given +connection+ in the ACPC
|
|
15
|
+
# format.
|
|
16
|
+
# @param [#write, #ready_to_write?] connection The connection through which the +action+
|
|
17
|
+
# should be sent.
|
|
18
|
+
# @param [#to_s] match_state The current match state.
|
|
19
|
+
# @param [#to_s] action The action to be sent through the +connection+.
|
|
20
|
+
# @return [Integer] The number of bytes written.
|
|
21
|
+
# @raise (see #validate_match_state)
|
|
22
|
+
# @raise (see #validate_action)
|
|
23
|
+
def self.send_action(connection, match_state, action)
|
|
24
|
+
validate_action action
|
|
25
|
+
|
|
26
|
+
full_action = "#{AcpcPokerTypes::MatchState.parse(match_state.to_s)}:#{action.to_s}"
|
|
27
|
+
connection.write full_action
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
# @raise IllegalActionFormat
|
|
33
|
+
def self.validate_action(action)
|
|
34
|
+
raise IllegalActionFormat unless self.valid_action?(action)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.valid_action?(action)
|
|
38
|
+
action.to_s.match(/^[#{AcpcPokerTypes::PokerAction::CONCATONATED_ACTIONS}]$/) ||
|
|
39
|
+
action.to_s.match(/^[#{CONCATENATED_MODIFIABLE_ACTIONS}]\d+$/)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
26
42
|
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
# @raise IllegalActionFormat
|
|
31
|
-
def self.validate_action(action)
|
|
32
|
-
raise IllegalActionFormat unless self.valid_action?(action)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def self.valid_action?(action)
|
|
36
|
-
all_actions = PokerAction::LEGAL_ACPC_CHARACTERS.to_a.join('')
|
|
37
|
-
modifiable_actions = PokerAction::MODIFIABLE_ACTIONS.values.to_a.join('')
|
|
38
|
-
|
|
39
|
-
action.to_acpc.match(/^[#{all_actions}]$/) || action.to_acpc.match(/^[#{modifiable_actions}]\d+$/)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
43
|
+
end
|