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.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +9 -29
  3. data/acpc_poker_basic_proxy.gemspec +13 -10
  4. data/lib/acpc_poker_basic_proxy.rb +2 -6
  5. data/lib/acpc_poker_basic_proxy/basic_proxy.rb +24 -22
  6. data/lib/acpc_poker_basic_proxy/communication_logic.rb +9 -0
  7. data/lib/acpc_poker_basic_proxy/communication_logic/acpc_dealer_communicator.rb +105 -101
  8. data/lib/acpc_poker_basic_proxy/communication_logic/acpc_dealer_information.rb +16 -12
  9. data/lib/acpc_poker_basic_proxy/communication_logic/action_sender.rb +37 -35
  10. data/lib/acpc_poker_basic_proxy/communication_logic/match_state_receiver.rb +12 -8
  11. data/lib/acpc_poker_basic_proxy/version.rb +1 -1
  12. data/spec/acpc_dealer_communicator_spec.rb +67 -0
  13. data/spec/acpc_dealer_information_spec.rb +10 -0
  14. data/spec/{communication_logic/action_sender_spec.rb → action_sender_spec.rb} +28 -33
  15. data/spec/basic_proxy_spec.rb +11 -5
  16. data/spec/coverage/index.html +1438 -0
  17. data/spec/match_state_receiver_spec.rb +38 -0
  18. data/spec/support/spec_helper.rb +30 -6
  19. metadata +170 -328
  20. data/spec/communication_logic/acpc_dealer_communicator_spec.rb +0 -61
  21. data/spec/communication_logic/acpc_dealer_information_spec.rb +0 -9
  22. data/spec/communication_logic/coverage/assets/0.5.3/app.js +0 -88
  23. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  24. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  25. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  26. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  27. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  28. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  29. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  30. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  31. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  32. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  33. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  34. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  35. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  36. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  37. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  38. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  39. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  40. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  41. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  42. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  43. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +0 -363
  44. data/spec/communication_logic/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
  45. data/spec/communication_logic/coverage/assets/0.5.3/favicon_green.png +0 -0
  46. data/spec/communication_logic/coverage/assets/0.5.3/favicon_red.png +0 -0
  47. data/spec/communication_logic/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  48. data/spec/communication_logic/coverage/assets/0.5.3/highlight.css +0 -129
  49. data/spec/communication_logic/coverage/assets/0.5.3/highlight.pack.js +0 -1
  50. data/spec/communication_logic/coverage/assets/0.5.3/jquery-1.6.2.min.js +0 -18
  51. data/spec/communication_logic/coverage/assets/0.5.3/jquery.dataTables.min.js +0 -152
  52. data/spec/communication_logic/coverage/assets/0.5.3/jquery.timeago.js +0 -141
  53. data/spec/communication_logic/coverage/assets/0.5.3/jquery.url.js +0 -174
  54. data/spec/communication_logic/coverage/assets/0.5.3/loading.gif +0 -0
  55. data/spec/communication_logic/coverage/assets/0.5.3/magnify.png +0 -0
  56. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  57. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  58. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  59. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  60. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  61. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  62. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  63. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  64. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  65. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  66. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  67. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  68. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  69. data/spec/communication_logic/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +0 -295
  70. data/spec/communication_logic/coverage/assets/0.5.3/stylesheet.css +0 -383
  71. data/spec/communication_logic/coverage/assets/0.7.1/application.css +0 -1110
  72. data/spec/communication_logic/coverage/assets/0.7.1/application.js +0 -626
  73. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/blank.gif +0 -0
  74. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_close.png +0 -0
  75. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_loading.png +0 -0
  76. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_nav_left.png +0 -0
  77. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_nav_right.png +0 -0
  78. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png +0 -0
  79. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png +0 -0
  80. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png +0 -0
  81. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png +0 -0
  82. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png +0 -0
  83. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png +0 -0
  84. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png +0 -0
  85. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png +0 -0
  86. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_title_left.png +0 -0
  87. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_title_main.png +0 -0
  88. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_title_over.png +0 -0
  89. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancy_title_right.png +0 -0
  90. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancybox-x.png +0 -0
  91. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancybox-y.png +0 -0
  92. data/spec/communication_logic/coverage/assets/0.7.1/fancybox/fancybox.png +0 -0
  93. data/spec/communication_logic/coverage/assets/0.7.1/favicon_green.png +0 -0
  94. data/spec/communication_logic/coverage/assets/0.7.1/favicon_red.png +0 -0
  95. data/spec/communication_logic/coverage/assets/0.7.1/favicon_yellow.png +0 -0
  96. data/spec/communication_logic/coverage/assets/0.7.1/loading.gif +0 -0
  97. data/spec/communication_logic/coverage/assets/0.7.1/magnify.png +0 -0
  98. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  99. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  100. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  101. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  102. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  103. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  104. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  105. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  106. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png +0 -0
  107. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  108. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png +0 -0
  109. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png +0 -0
  110. data/spec/communication_logic/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  111. data/spec/communication_logic/coverage/index.html +0 -72
  112. data/spec/communication_logic/match_state_receiver_spec.rb +0 -37
  113. 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
- require 'bundler/gem_tasks'
2
- require 'rake'
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
- task :build => :spec do
15
- system "gem build acpc_poker_basic_proxy.gemspec"
16
- end
4
+ require 'rake'
5
+ require 'rake/testtask'
17
6
 
18
- task :tag => :build do
19
- tag_gem_version AcpcPokerBasicProxy::VERSION
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 tasks.rb README.md)
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 'rspec'
23
- s.add_development_dependency 'mocha'
24
- s.add_development_dependency 'simplecov'
25
- s.add_development_dependency 'acpc_dealer_data'
26
- s.add_development_dependency 'acpc_dealer'
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 File.expand_path("../acpc_poker_basic_proxy/version", __FILE__)
1
+ require 'acpc_poker_basic_proxy/version'
2
2
 
3
- require File.expand_path("../acpc_poker_basic_proxy/basic_proxy", __FILE__)
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 File.expand_path('../communication_logic/acpc_dealer_communicator', __FILE__)
3
- require File.expand_path('../communication_logic/acpc_dealer_information', __FILE__)
4
- require File.expand_path('../communication_logic/action_sender', __FILE__)
5
- require File.expand_path('../communication_logic/match_state_receiver', __FILE__)
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
- class BasicProxy
9
- exceptions :initial_match_state_not_yet_received
8
+ module AcpcPokerBasicProxy
9
+ class BasicProxy
10
+ exceptions :initial_match_state_not_yet_received
10
11
 
11
- # @param [AcpcDealerInformation] dealer_information Information about the dealer to which this bot should connect.
12
- def initialize(dealer_information)
13
- @dealer_communicator = AcpcDealerCommunicator.new dealer_information.port_number, dealer_information.host_name, dealer_information.millisecond_response_timeout
14
- end
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
- # @param [PokerAction] action The action to be sent.
17
- # @return (see ActionSender#send_action)
18
- # @raise InitialMatchStateNotYetReceived
19
- # @raise (see ActionSender#send_action)
20
- def send_action(action)
21
- raise InitialMatchStateNotYetReceived unless @match_state
22
- ActionSender.send_action @dealer_communicator, @match_state, action
23
- end
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
- # @see MatchStateReceiver#receive_match_state
26
- def receive_match_state!
27
- @match_state = MatchStateReceiver.receive_match_state @dealer_communicator
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 File.expand_path('../../mixins/socket_with_ready_methods', __FILE__)
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
- class AcpcDealerCommunicator
12
- exceptions :acpc_dealer_connection_error, :put_to_acpc_dealer_error, :get_from_acpc_dealer_error
13
-
14
- # @return [String] The ACPC dealer version label.
15
- VERSION_LABEL = 'VERSION'
16
-
17
- # @return [Hash] The ACPC dealer version numbers.
18
- VERSION_NUMBERS = {:major => 2, :minor => 0, :revision => 0}
19
-
20
- # @return [String] Dealer specified string terminator.
21
- TERMINATION_STRING = "\r\n"
22
-
23
- # @param [Integer] port The port on which to connect to the dealer.
24
- # @param [String] host_name The host on which the dealer is running.
25
- # @param [Integer] millisecond_response_timeout The dealer's response timeout, in milleseconds.
26
- # @raise AcpcDealerConnectionError, PutToAcpcDealerError
27
- def initialize(port, host_name='localhost', millisecond_response_timeout=nil)
28
- begin
29
- @dealer_socket = TCPSocket.new(host_name, port)
30
- @response_timeout_in_seconds = if millisecond_response_timeout
31
- millisecond_response_timeout/(10**3)
32
- else
33
- nil
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
- # Closes the connection to the dealer.
44
- def close
45
- @dealer_socket.close if @dealer_socket
46
- end
45
+ # Closes the connection to the dealer.
46
+ def close
47
+ @dealer_socket.close if @dealer_socket
48
+ end
47
49
 
48
- # Retrieves a string from the dealer.
49
- #
50
- # @return [String] A string from the dealer.
51
- # @raise GetFromAcpcDealerError
52
- def gets
53
- begin
54
- raw_match_state = string_from_dealer
55
- rescue
56
- handle_error GetFromAcpcDealerError, "Unable to get a string from the dealer: #{$?}"
57
- end
58
- raw_match_state
59
- end
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
- # Sends a given +string+ to the dealer.
62
- #
63
- # @param [String] string The string to send.
64
- # @return (see #send_string_to_dealer)
65
- # @raise WriteToAcpcDealerError
66
- def write(string)
67
- begin
68
- bytes_written = send_string_to_dealer string
69
- rescue
70
- handle_error GetFromAcpcDealerError, "Unable to send the string, \"#{string}\", to the dealer: #{$?}."
71
- end
72
- bytes_written
73
- end
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
- # @see TCPSocket#ready_to_write?
76
- def ready_to_write?
77
- @dealer_socket.ready_to_write? @response_timeout_in_seconds
78
- end
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
- # @see TCPSocket#ready_to_read?
81
- def ready_to_read?
82
- @dealer_socket.ready_to_read? @response_timeout_in_seconds
83
- end
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
- private
87
+ private
86
88
 
87
- def handle_error(exception, message)
88
- close
89
- raise exception, message
90
- end
89
+ def handle_error(exception, message)
90
+ close
91
+ raise exception, message
92
+ end
91
93
 
92
- # @return (see #send_string_to_dealer)
93
- def send_version_string_to_dealer
94
- version_string = "#{VERSION_LABEL}:#{VERSION_NUMBERS[:major]}.#{VERSION_NUMBERS[:minor]}.#{VERSION_NUMBERS[:revision]}"
95
- begin
96
- bytes_written = send_string_to_dealer version_string
97
- rescue
98
- handle_error PutToAcpcDealerError, "Unable to send version string, \"#{version_string}\", to the dealer"
99
- end
100
- bytes_written
101
- end
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
- # @return [Integer] The number of bytes written to the dealer.
104
- def send_string_to_dealer(string)
105
- raise unless ready_to_write?
106
- begin
107
- bytes_written = @dealer_socket.write(string + TERMINATION_STRING)
108
- rescue
109
- raise
110
- end
111
- bytes_written
112
- end
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
- def string_from_dealer
115
- raise unless ready_to_read?
116
- begin
117
- string = @dealer_socket.gets.chomp
118
- rescue
119
- raise
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
- class AcpcDealerInformation
4
- # @return [String] The host name of the dealer associated with this table.
5
- attr_reader :host_name
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
- # @return [Integer] The port number of the dealer associated with this table.
8
- attr_reader :port_number
9
+ # @return [Integer] The port number of the dealer associated with this table.
10
+ attr_reader :port_number
9
11
 
10
- # @return [Integer] The dealer's response timeout.
11
- attr_reader :millisecond_response_timeout
12
+ # @return [Integer] The dealer's response timeout.
13
+ attr_reader :millisecond_response_timeout
12
14
 
13
- def initialize(host_name, port_number, millisecond_response_timeout=nil)
14
- @host_name = host_name
15
- @port_number = port_number
16
- @millisecond_response_timeout = millisecond_response_timeout
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/rank'
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
- class ActionSender
9
-
10
- exceptions :illegal_action_format
11
-
12
- # Sends the given +action+ to through the given +connection+ in the ACPC
13
- # format.
14
- # @param [#write, #ready_to_write?] connection The connection through which the +action+
15
- # should be sent.
16
- # @param [#to_s] match_state The current match state.
17
- # @param [#to_acpc] action The action to be sent through the +connection+.
18
- # @return [Integer] The number of bytes written.
19
- # @raise (see #validate_match_state)
20
- # @raise (see #validate_action)
21
- def self.send_action(connection, match_state, action)
22
- validate_action action
23
-
24
- full_action = "#{MatchState.parse(match_state.to_s)}:#{action.to_acpc}"
25
- connection.write full_action
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