def __init__(self, gid: str, red: Agent, blue: Agent, board: GameBoard = None, state: GameState = None, seed: int = 42, useLoggers: bool = True): """ Initialize the state-machine. :param gid: Unique identifier. :param board: Static descriptor of the game. :param state: Dynamic descriptor of the game. :param red: String value of the player to use. Check module agent.interactive for a list. :param blue: String value of the player to use. Check module agent.interactive for a list. :param seed: Random seed value (default: 42) """ if useLoggers: self.logger = logging.getLogger(__name__) else: self.logger = logging.getLogger("internal") self.gid: str = gid self.seed: int = seed self.actions_history: List[Action] = [] self.states_history: List[GameState] = [] self.outcome: List[Outcome] = [] self.winner: str = '' self.end: bool = False self.update: bool = False self.board: GameBoard = board self.state: GameState = state self.origin: GameState = deepcopy(state) self.gm: GameManager = GameManager() self.red: Agent = red self.blue: Agent = blue self.humans: bool = isinstance(self.red, Human) or isinstance( self.blue, Human) self.first = None self.second = None self.step = self._goInit
def __init__(self, name: str, team: str, seed: int = 0): """ :param name: name of this agent :param team: color of the team :param seed: random seed to use internally """ self.name: str = name self.team: str = team self.seed: int = seed self.count: int = 0 # history of registered actions used to build the dataframe of actions performed self.history: list = [] # internal game manager self.gm: GameManager = GameManager()
import unittest from core.actions import Move from core.const import RED, BLUE from core.figures import buildFigure from core.game import GameBoard, GameState, GoalMaxTurn, GoalReachPoint, GoalEliminateOpponent, GameManager from core.utils.coordinates import Hex GM: GameManager = GameManager() class TestGoals(unittest.TestCase): def setUp(self): shape = (8, 8) self.board = GameBoard(shape) self.state = GameState(shape) self.blue_tank = buildFigure('Tank', (6, 4), BLUE) self.red_tank = buildFigure('Tank', (1, 4), RED) self.red_inf = buildFigure('Infantry', (2, 4), RED) self.state.addFigure(self.red_tank, self.red_inf, self.blue_tank) def testEliminateOpponent(self): g = GoalEliminateOpponent(RED, BLUE) self.assertFalse(g.check(self.state), 'before attack, blue unit is still alive!') self.blue_tank.killed = True