Skip to content

Commit 80b86ad

Browse files
committed
UndefinedOperationError for game.player.{actions,infosets} on non-tree
1 parent c9c00d5 commit 80b86ad

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/pygambit/player.pxi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,34 @@ class Player:
228228
previously, information sets were (expensively) re-sorted after every change
229229
to the game tree.
230230

231+
Raises
232+
------
233+
UndefinedOperationError
234+
If the game does not have a tree representation.
235+
231236
See also
232237
--------
233238
Game.sort_infosets
234239
"""
240+
if not self.game.is_tree:
241+
raise UndefinedOperationError(
242+
"Operation only defined for games with a tree representation"
243+
)
235244
return PlayerInfosets.wrap(self.player)
236245

237246
@property
238247
def actions(self) -> PlayerActions:
239-
"""Returns the set of actions available to the player at some information set."""
248+
"""Returns the set of actions available to the player at some information set.
249+
250+
Raises
251+
------
252+
UndefinedOperationError
253+
If the game does not have a tree representation.
254+
"""
255+
if not self.game.is_tree:
256+
raise UndefinedOperationError(
257+
"Operation only defined for games with a tree representation"
258+
)
240259
return PlayerActions.wrap(self)
241260

242261
@property

tests/test_strategic.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,24 @@ def test_strategic_game_actions():
1111
_ = game.actions
1212

1313

14+
def test_strategic_game_player_actions():
15+
game = gbt.Game.new_table([2, 2])
16+
with pytest.raises(gbt.UndefinedOperationError):
17+
_ = game.players[0].actions
18+
19+
1420
def test_strategic_game_infosets():
1521
game = gbt.Game.new_table([2, 2])
1622
with pytest.raises(gbt.UndefinedOperationError):
1723
_ = game.infosets
1824

1925

26+
def test_strategic_game_player_infosets():
27+
game = gbt.Game.new_table([2, 2])
28+
with pytest.raises(gbt.UndefinedOperationError):
29+
_ = game.players[0].infosets
30+
31+
2032
def test_strategic_game_root():
2133
game = gbt.Game.new_table([2, 2])
2234
with pytest.raises(gbt.UndefinedOperationError):

0 commit comments

Comments
 (0)