@@ -169,18 +169,20 @@ def estimated_size(self):
169
169
return size
170
170
171
171
172
- def test_graph_is_connected (edges , players ):
172
+ def graph_is_connected (edges , players ):
173
173
"""
174
174
Test if a set of edges defines a complete graph on a set of players.
175
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.
176
+ This is used by the spatial tournaments.
178
177
179
178
Parameters:
180
179
-----------
180
+ edges : a list of 2 tuples
181
+ players : a list of player names
181
182
182
- edges : a list of 2 tuples
183
- players : a list of player names
183
+ Returns:
184
+ --------
185
+ boolean : True if the graph is connected
184
186
"""
185
187
# Check if all players are connected.
186
188
player_indices = set (range (len (players )))
@@ -189,8 +191,7 @@ def test_graph_is_connected(edges, players):
189
191
for node in edge :
190
192
node_indices .add (node )
191
193
192
- if player_indices != node_indices :
193
- raise ValueError ("The graph edges do not include all players." )
194
+ return player_indices == node_indices
194
195
195
196
196
197
@@ -217,7 +218,8 @@ class SpatialMatches(RoundRobinMatches):
217
218
218
219
def __init__ (self , players , turns , game , repetitions , edges ):
219
220
220
- test_graph_is_connected (edges , players )
221
+ if not graph_is_connected (edges , players ):
222
+ raise ValueError ("The graph edges do not include all players." )
221
223
self .edges = edges
222
224
super (SpatialMatches , self ).__init__ (players , turns , game , repetitions )
223
225
@@ -254,7 +256,8 @@ class ProbEndSpatialMatches(SpatialMatches, ProbEndRoundRobinMatches):
254
256
255
257
def __init__ (self , players , prob_end , game , repetitions , noise , edges ):
256
258
257
- test_graph_is_connected (edges , players )
259
+ if not graph_is_connected (edges , players ):
260
+ raise ValueError ("The graph edges do not include all players." )
258
261
self .edges = edges
259
262
ProbEndRoundRobinMatches .__init__ (self , players , prob_end ,
260
263
game , repetitions , noise )
0 commit comments