@@ -169,6 +169,31 @@ def estimated_size(self):
169
169
return size
170
170
171
171
172
+ def test_graph_is_connected (edges , players ):
173
+ """
174
+ Test if a set of edges defines a complete graph on a set of players.
175
+
176
+ This is used by the spatial tournaments and will raise a ValueError if the
177
+ graph would have some players not playing anyone.
178
+
179
+ Parameters:
180
+ -----------
181
+
182
+ edges : a list of 2 tuples
183
+ players : a list of player names
184
+ """
185
+ # Check if all players are connected.
186
+ player_indices = set (range (len (players )))
187
+ node_indices = set ()
188
+ for edge in edges :
189
+ for node in edge :
190
+ node_indices .add (node )
191
+
192
+ if player_indices != node_indices :
193
+ raise ValueError ("The graph edges do not include all players." )
194
+
195
+
196
+
172
197
class SpatialMatches (RoundRobinMatches ):
173
198
"""
174
199
A class that generates spatially-structured matches.
@@ -192,16 +217,7 @@ class SpatialMatches(RoundRobinMatches):
192
217
193
218
def __init__ (self , players , turns , game , repetitions , edges ):
194
219
195
- # Check if all players are connected.
196
- player_indices = set (range (len (players )))
197
- node_indices = set ()
198
- for edge in edges :
199
- for node in edge :
200
- node_indices .add (node )
201
-
202
- if player_indices != node_indices :
203
- raise ValueError ("The graph edges do not include all players." )
204
-
220
+ test_graph_is_connected (edges , players )
205
221
self .edges = edges
206
222
super (SpatialMatches , self ).__init__ (players , turns , game , repetitions )
207
223
@@ -238,16 +254,7 @@ class ProbEndSpatialMatches(SpatialMatches, ProbEndRoundRobinMatches):
238
254
239
255
def __init__ (self , players , prob_end , game , repetitions , noise , edges ):
240
256
241
- # Check if all players are connected.
242
- player_indices = set (range (len (players )))
243
- node_indices = set ()
244
- for edge in edges :
245
- for node in edge :
246
- node_indices .add (node )
247
-
248
- if player_indices != node_indices :
249
- raise ValueError ("The graph edges do not include all players." )
250
-
257
+ test_graph_is_connected (edges , players )
251
258
self .edges = edges
252
259
ProbEndRoundRobinMatches .__init__ (self , players , prob_end ,
253
260
game , repetitions , noise )
0 commit comments