Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/pygambit/game.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,16 @@ class Game:
.. versionchanged:: 16.4
Changed from a method ``nodes()`` to a property.

Raises
------
UndefinedOperationError
If the game does not have a tree representation.
"""
if not self.is_tree:
raise UndefinedOperationError(
"Operation only defined for games with a tree representation"
)

return GameNodes.wrap(self.game)

@property
Expand Down Expand Up @@ -1885,11 +1894,20 @@ class Game:

.. versionadded:: 16.4.0

Raises
------
UndefinedOperationError
If the game does not have a tree representation.

See also
--------
Player.infosets
Infoset.members
"""
if not self.is_tree:
raise UndefinedOperationError(
"Operation only defined for games with a tree representation"
)
self.game.deref().SortInfosets()

def add_player(self, label: str = "") -> Player:
Expand Down
21 changes: 20 additions & 1 deletion src/pygambit/player.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,34 @@ class Player:
previously, information sets were (expensively) re-sorted after every change
to the game tree.

Raises
------
UndefinedOperationError
If the game does not have a tree representation.

See also
--------
Game.sort_infosets
"""
if not self.game.is_tree:
raise UndefinedOperationError(
"Operation only defined for games with a tree representation"
)
return PlayerInfosets.wrap(self.player)

@property
def actions(self) -> PlayerActions:
"""Returns the set of actions available to the player at some information set."""
"""Returns the set of actions available to the player at some information set.

Raises
------
UndefinedOperationError
If the game does not have a tree representation.
"""
if not self.game.is_tree:
raise UndefinedOperationError(
"Operation only defined for games with a tree representation"
)
return PlayerActions.wrap(self)

@property
Expand Down
21 changes: 20 additions & 1 deletion tests/test_strategic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ def test_strategic_game_actions():
_ = game.actions


def test_strategic_game_player_actions():
game = gbt.Game.new_table([2, 2])
with pytest.raises(gbt.UndefinedOperationError):
_ = game.players[0].actions


def test_strategic_game_infosets():
game = gbt.Game.new_table([2, 2])
with pytest.raises(gbt.UndefinedOperationError):
_ = game.infosets


def test_strategic_game_player_infosets():
game = gbt.Game.new_table([2, 2])
with pytest.raises(gbt.UndefinedOperationError):
_ = game.players[0].infosets


def test_strategic_game_root():
game = gbt.Game.new_table([2, 2])
with pytest.raises(gbt.UndefinedOperationError):
Expand All @@ -25,7 +37,14 @@ def test_strategic_game_root():

def test_strategic_game_nodes():
game = gbt.Game.new_table([2, 2])
assert list(game.nodes) == []
with pytest.raises(gbt.UndefinedOperationError):
_ = game.nodes


def test_strategic_game_sort_infosets():
game = gbt.Game.new_table([2, 2])
with pytest.raises(gbt.UndefinedOperationError):
_ = game.sort_infosets()


def test_game_behav_profile_error():
Expand Down