Skip to content

Commit

Permalink
feat: change Agent.result to return an action or sequence of actions
Browse files Browse the repository at this point in the history
  • Loading branch information
SverreNystad committed Apr 9, 2024
1 parent 98499a7 commit 24cbd10
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,32 @@ class for all agents in the simulation.
"""

from abc import ABC, abstractmethod
from typing import Any
from typing import Any, Union

from src.game.board import Action, Board

from src.game.board import Board

class Agent(ABC):
"""Base class for all agents in the simulation."""

@classmethod
def __instancecheck__(cls, instance: Any) -> bool:
return cls.__subclasscheck__(type(instance))

@classmethod
def __subclasscheck__(cls, subclass: Any) -> bool:
return (
hasattr(subclass, 'result') and
callable(subclass.result)
)
return hasattr(subclass, "result") and callable(subclass.result)

@abstractmethod
def result(board: Board) -> Board:
def result(board: Board) -> Union[Action, list[Action]]:
"""
Determines the next move for the agent based on the current state of the board.
Args:
board (Board): The current state of the board.
Returns:
The new state of the board after the agent has made a move.
The next move for the agent. This can be a single action or a list of actions.
"""
pass

0 comments on commit 24cbd10

Please sign in to comment.