Skip to content

nhra_gt.interfaces

Protocol and interface definitions.

Classes

ExtensiveFormGame

Bases: Protocol

Protocol for an extensive-form (tree) game.

Source code in src/nhra_gt/interfaces/protocols.py
@runtime_checkable
class ExtensiveFormGame(Protocol):
    """Protocol for an extensive-form (tree) game."""

    def is_terminal(self, state: Any) -> bool: ...  # pragma: no cover
    def get_payoffs(self, state: Any) -> FloatArray: ...  # pragma: no cover
    def get_legal_actions(self, state: Any) -> list[Any]: ...  # pragma: no cover

NormalFormGame

Bases: Protocol

Protocol for a normal-form game container.

Source code in src/nhra_gt/interfaces/protocols.py
@runtime_checkable
class NormalFormGame(Protocol):
    """Protocol for a normal-form game container."""

    @property
    def num_players(self) -> int:  # pragma: no cover
        """Number of players in the game."""
        ...

    def payoffs(self, actions: IntArray) -> FloatArray:  # pragma: no cover
        """
        Calculate payoffs for all players given an action profile.

        Args:
            actions: An array of actions, one for each player.

        Returns:
            An array of payoffs, one for each player.
        """
        ...

Attributes

num_players property

Number of players in the game.

Functions

payoffs(actions)

Calculate payoffs for all players given an action profile.

Parameters:

Name Type Description Default
actions IntArray

An array of actions, one for each player.

required

Returns:

Type Description
FloatArray

An array of payoffs, one for each player.

Source code in src/nhra_gt/interfaces/protocols.py
def payoffs(self, actions: IntArray) -> FloatArray:  # pragma: no cover
    """
    Calculate payoffs for all players given an action profile.

    Args:
        actions: An array of actions, one for each player.

    Returns:
        An array of payoffs, one for each player.
    """
    ...

Strategy

Bases: Protocol

Protocol for a game-theory strategy (e.g., mixed or pure).

Source code in src/nhra_gt/interfaces/protocols.py
@runtime_checkable
class Strategy(Protocol):
    """Protocol for a game-theory strategy (e.g., mixed or pure)."""

    def sample(self) -> Any:  # pragma: no cover
        """Sample an action from the strategy."""
        ...

    def probability(self, action: Any) -> float:  # pragma: no cover
        """Get the probability of a specific action."""
        ...

Functions

sample()

Sample an action from the strategy.

Source code in src/nhra_gt/interfaces/protocols.py
def sample(self) -> Any:  # pragma: no cover
    """Sample an action from the strategy."""
    ...
probability(action)

Get the probability of a specific action.

Source code in src/nhra_gt/interfaces/protocols.py
def probability(self, action: Any) -> float:  # pragma: no cover
    """Get the probability of a specific action."""
    ...