acpc_table_manager 3.0.13 → 3.0.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3019d716b6b2e7b2b460c7d6116ff66fff0d900
4
- data.tar.gz: bd97b8a4c88d08bbef9f2a097e9868fa20fb9aa6
3
+ metadata.gz: caa21a432272320af6b1c4c92c1101224ab17c4c
4
+ data.tar.gz: 41195e4e8d2026cdec9e66ec8c2dc24814370751
5
5
  SHA512:
6
- metadata.gz: e087449d3f52909bc0965b8938384e1073222fef34e02ad675f7eda47f360db6c91a2c002fbefdacac7783c5e836c959bb72fccc1b3f0a4d32266cdf9df263aa
7
- data.tar.gz: 1b208ddf1c6e8e16b28e5d6241f585ae28b0896407d715b35ef9541db3cd6fab89d160d66a0c8223c9041aa77170c15d57b41c8aa957369d1e0cb03c691d9309
6
+ metadata.gz: 68d5270916d22bb56b2e335caca6ab7a6e35c4b74d01f7c7b088f33b8705619e175435425eea18263f4410eaa8c8f1b81efa36f27a2269e9529eee69393d95f5
7
+ data.tar.gz: d3b1f355a8969e54492baec90b5ef0d671394622f74d7765c6963a31db4540c9778812d0b25ec2e9c166434df0c91adb618535a736d17455e872537d9b4b88be
@@ -183,6 +183,7 @@ class Match
183
183
  end
184
184
  def new_random_seed
185
185
  # The ACPC dealer requires 32 bit random seeds
186
+ # TODO The bound to rand is exclusive so this should be 2**33
186
187
  rand(2**33 - 1)
187
188
  end
188
189
  def new_random_seat(num_players)
@@ -27,31 +27,27 @@ module AcpcTableManager
27
27
 
28
28
  log(
29
29
  __method__,
30
- {
31
- game_definition_key: @game_definition_key,
32
- max_num_matches: AcpcTableManager.exhibition_config.games[@game_definition_key]['max_num_matches']
33
- }
30
+ game_definition_key: @game_definition_key,
31
+ max_num_matches: AcpcTableManager.exhibition_config.games[@game_definition_key]['max_num_matches']
34
32
  )
35
33
  end
36
34
 
37
35
  def start_players!(match)
38
36
  Opponents.start(match)
39
- log(__method__, msg: "Opponents started for #{match.id.to_s}")
37
+ log(__method__, msg: "Opponents started for #{match.id}")
40
38
 
41
39
  start_proxy! match
42
40
  end
43
41
 
44
42
  def start_proxy!(match)
45
- command = "#{File.expand_path('../../../exe/acpc_proxy', __FILE__)} -t #{AcpcTableManager.config_file} -m #{match.id.to_s}"
43
+ command = "#{File.expand_path('../../../exe/acpc_proxy', __FILE__)} -t #{AcpcTableManager.config_file} -m #{match.id}"
46
44
  log(
47
45
  __method__,
48
- {
49
- msg: "Starting proxy for #{match.id.to_s}",
50
- command: command
51
- }
46
+ msg: "Starting proxy for #{match.id}",
47
+ command: command
52
48
  )
53
49
 
54
- match.proxy_pid = Timeout::timeout(3) do
50
+ match.proxy_pid = Timeout.timeout(3) do
55
51
  pid = Process.spawn(command)
56
52
  Process.detach(pid)
57
53
  pid
@@ -60,15 +56,15 @@ module AcpcTableManager
60
56
 
61
57
  log(
62
58
  __method__,
63
- {
64
- msg: "Started proxy for \"#{match.name}\" (#{match.id.to_s})",
65
- pid: match.proxy_pid
66
- }
59
+ msg: "Started proxy for \"#{match.name}\" (#{match.id})",
60
+ pid: match.proxy_pid
67
61
  )
68
62
  self
69
63
  end
70
64
 
71
- def matches_to_start() my_matches.queue end
65
+ def matches_to_start
66
+ my_matches.queue
67
+ end
72
68
 
73
69
  def my_matches
74
70
  Match.where(game_definition_key: @game_definition_key.to_sym)
@@ -80,7 +76,9 @@ module AcpcTableManager
80
76
  prevNumMatchesRunning != Match.running(my_matches).length
81
77
  end
82
78
 
83
- def length() matches_to_start.length end
79
+ def length
80
+ matches_to_start.length
81
+ end
84
82
 
85
83
  def available_special_ports
86
84
  if AcpcTableManager.exhibition_config.special_ports_to_dealer
@@ -91,32 +89,40 @@ module AcpcTableManager
91
89
  end
92
90
 
93
91
  def check!
92
+ return if length < 1
93
+
94
94
  my_matches_to_start = matches_to_start.to_a
95
- num_running_matches = Match.running(my_matches).length
96
- log(
97
- __method__,
98
- {
99
- num_running_matches: num_running_matches,
100
- num_matches_to_start: my_matches_to_start.length
101
- }
102
- )
95
+
96
+ max_running_matches = AcpcTableManager.exhibition_config.games[@game_definition_key]['max_num_matches']
97
+ check_num_running_matches = max_running_matches > 0
98
+
99
+ num_running_matches = 0
100
+ if check_num_running_matches
101
+ num_running_matches = Match.running(my_matches).length
102
+ log(
103
+ __method__,
104
+ num_running_matches: num_running_matches,
105
+ num_matches_to_start: my_matches_to_start.length
106
+ )
107
+ end
103
108
 
104
109
  matches_started = []
105
- while (
110
+ while
106
111
  !my_matches_to_start.empty? &&
107
- num_running_matches < AcpcTableManager.exhibition_config.games[@game_definition_key]['max_num_matches']
108
- )
112
+ (
113
+ !check_num_running_matches ||
114
+ num_running_matches < max_running_matches
115
+ )
116
+
109
117
  matches_started << dequeue(my_matches_to_start.pop)
110
118
  num_running_matches += 1
111
119
  end
112
120
 
113
121
  log(
114
122
  __method__,
115
- {
116
- matches_started: matches_started,
117
- num_running_matches: num_running_matches,
118
- num_matches_to_start: matches_to_start.length
119
- }
123
+ matches_started: matches_started,
124
+ num_running_matches: num_running_matches,
125
+ num_matches_to_start: matches_to_start.length
120
126
  )
121
127
 
122
128
  matches_started
@@ -126,14 +132,14 @@ module AcpcTableManager
126
132
 
127
133
  def port(available_ports)
128
134
  port_ = available_ports.pop
129
- while !AcpcDealer::port_available?(port_)
135
+ until AcpcDealer.port_available?(port_)
130
136
  if available_ports.empty?
131
- raise NoPortForDealerAvailable.new("None of the special ports (#{available_special_ports}) are open")
137
+ raise NoPortForDealerAvailable, "None of the special ports (#{available_special_ports}) are open"
132
138
  end
133
139
  port_ = available_ports.pop
134
140
  end
135
141
  unless port_
136
- raise NoPortForDealerAvailable.new("None of the special ports (#{available_special_ports}) are open")
142
+ raise NoPortForDealerAvailable, "None of the special ports (#{available_special_ports}) are open"
137
143
  end
138
144
  port_
139
145
  end
@@ -148,7 +154,7 @@ module AcpcTableManager
148
154
  0
149
155
  end
150
156
  end
151
- return ports, available_ports
157
+ [ports, available_ports]
152
158
  end
153
159
 
154
160
  # @return [Object] The match that has been started or +nil+ if none could
@@ -170,7 +176,7 @@ module AcpcTableManager
170
176
  num_repetitions = 0
171
177
  dealer_info = nil
172
178
 
173
- while dealer_info.nil? do
179
+ while dealer_info.nil?
174
180
  log(
175
181
  __method__,
176
182
  msg: "Added #{match.id} list of running matches",
@@ -183,7 +189,7 @@ module AcpcTableManager
183
189
  rescue Timeout::Error => e
184
190
  log(
185
191
  __method__,
186
- {warning: "The dealer for match \"#{match.name}\" (#{match.id}) timed out."},
192
+ { warning: "The dealer for match \"#{match.name}\" (#{match.id}) timed out." },
187
193
  Logger::Severity::WARN
188
194
  )
189
195
  begin
@@ -192,7 +198,7 @@ module AcpcTableManager
192
198
  available_ports = available_special_ports
193
199
  log(
194
200
  __method__,
195
- {warning: "#{ports_to_be_used} ports unavailable, retrying with all special ports, #{available_ports}."},
201
+ { warning: "#{ports_to_be_used} ports unavailable, retrying with all special ports, #{available_ports}." },
196
202
  Logger::Severity::WARN
197
203
  )
198
204
  end
@@ -200,14 +206,14 @@ module AcpcTableManager
200
206
  sleep 1
201
207
  log(
202
208
  __method__,
203
- {warning: "Retrying with all special ports, #{available_ports}."},
209
+ { warning: "Retrying with all special ports, #{available_ports}." },
204
210
  Logger::Severity::WARN
205
211
  )
206
212
  num_repetitions += 1
207
213
  else
208
214
  log(
209
215
  __method__,
210
- {warning: "Unable to start match after retry, giving up."},
216
+ { warning: 'Unable to start match after retry, giving up.' },
211
217
  Logger::Severity::ERROR
212
218
  )
213
219
  match.unable_to_start_dealer = true
@@ -1,3 +1,3 @@
1
1
  module AcpcTableManager
2
- VERSION = "3.0.13"
2
+ VERSION = '3.0.14'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acpc_table_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.13
4
+ version: 3.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Morrill
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-16 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pony