chessai.agents.scripted

 1import typing
 2
 3import chessai.core.action
 4import chessai.core.agent
 5import chessai.core.gamestate
 6
 7class ScriptedAgent(chessai.core.agent.Agent):
 8    """
 9    An agent that has a specific set of actions that they will do in order.
10    Once the actions are exhausted, they will just stop.
11    This agent will try to take a scripted action even if it is illegal.
12
13    This agent is particularly useful for things like replays.
14    """
15
16    def __init__(self,
17            actions: list[chessai.core.action.Action] | None = None,
18            **kwargs: typing.Any) -> None:
19        super().__init__(**kwargs)
20
21        if (actions is None):
22            actions = []
23
24        self._actions: list[chessai.core.action.Action] = actions
25        """ The scripted actions this agent will take. """
26
27    def get_action(self, state: chessai.core.gamestate.GameState) -> chessai.core.action.Action:
28        if (len(self._actions) > 0):
29            return self._actions.pop(0)
30
31        return chessai.core.action.NoneAction()
class ScriptedAgent(chessai.core.agent.Agent):
 8class ScriptedAgent(chessai.core.agent.Agent):
 9    """
10    An agent that has a specific set of actions that they will do in order.
11    Once the actions are exhausted, they will just stop.
12    This agent will try to take a scripted action even if it is illegal.
13
14    This agent is particularly useful for things like replays.
15    """
16
17    def __init__(self,
18            actions: list[chessai.core.action.Action] | None = None,
19            **kwargs: typing.Any) -> None:
20        super().__init__(**kwargs)
21
22        if (actions is None):
23            actions = []
24
25        self._actions: list[chessai.core.action.Action] = actions
26        """ The scripted actions this agent will take. """
27
28    def get_action(self, state: chessai.core.gamestate.GameState) -> chessai.core.action.Action:
29        if (len(self._actions) > 0):
30            return self._actions.pop(0)
31
32        return chessai.core.action.NoneAction()

An agent that has a specific set of actions that they will do in order. Once the actions are exhausted, they will just stop. This agent will try to take a scripted action even if it is illegal.

This agent is particularly useful for things like replays.

ScriptedAgent( actions: list[chessai.core.action.Action] | None = None, **kwargs: Any)
17    def __init__(self,
18            actions: list[chessai.core.action.Action] | None = None,
19            **kwargs: typing.Any) -> None:
20        super().__init__(**kwargs)
21
22        if (actions is None):
23            actions = []
24
25        self._actions: list[chessai.core.action.Action] = actions
26        """ The scripted actions this agent will take. """
def get_action( self, state: chessai.core.gamestate.GameState) -> chessai.core.action.Action:
28    def get_action(self, state: chessai.core.gamestate.GameState) -> chessai.core.action.Action:
29        if (len(self._actions) > 0):
30            return self._actions.pop(0)
31
32        return chessai.core.action.NoneAction()

Get an action for this agent given the current state of the game. This is simplified version of get_action_full(), see that method for full details.