def start(self, agentX: Agent, agentY: Agent, first: Unit, seed=0): #start_game """ start new or restart current game @param first: Unit @param agentX: Agent @param agentY: Agent """ self.__logging_game = False #SETTINGS.get("logs/game") self.__logging_brief = SETTINGS.get("logs/brief") #TODO: fix logging self.__agentX = agentX self.__agentY = agentY self.__running = True self.__turn = 0 if seed == 0: chance = self.__dice.roll() self.__sticks = tuple(self.__dice.sticks) self.__ply = Ply(chance=chance, agent=first) else: s = _State(seed) chance = s.steps() if chance == 0: chance = self.__dice.roll() self.__sticks = tuple(self.__dice.sticks) self.__ply = Ply(state=s, chance=chance, agent=first) else: self.__ply = Ply(seed=seed) if self.__logging_game: headers = f"N;{agentX._name} vs {agentY._name}: agent;steps;utility;seed\n" self._gamelog = Report("game", "csv", "logs/games", headers) self.__game_starttime = perf_counter() self.__onmove() self.__run() self.__stop()
def check_seed(seed): if type(seed) is not int: return False try: test = Ply(seed=seed) res = True if test.expectation in (0, 1): res = False if set(test.board) != {Unit.X, Unit.Y, Unit.NONE}: res = False if test.board.count(Unit.NONE) < 20: res = False return res except: return False
def test_strats(self): p = Ply(chance=1) self.assertTrue(p.strategies.actions[0] == Action.ATTACK)
def test_steps(self): p = Ply(chance=1) self.assertEqual(p.steps,1)
def test_state(self): p = Ply(chance=1) self.assertIsInstance(p.state,(StrategyNode,))
def test_seed(self): p = Ply(chance=1) self.assertIsInstance(p.seed,(int,))
def test_increment(self): p = Ply(chance=1) self.assertIsInstance(p.increment(0,1), (Ply,))
def test_expectation(self): p = Ply(chance=1) self.assertIsInstance(p.expectation,(float,))
def test_event(self): p = Ply(chance=1) self.assertIsInstance(p.event,(Ply.Event,))
def test_board(self): p = Ply(chance=1) self.assertEqual(p.board[0], Unit.X) self.assertEqual(p.board[29], Unit.NONE)
def test_agent(self): p = Ply(chance=1) self.assertEqual(p.agent, Unit.X)
def test_call(self): p = Ply(chance=1) e = Emax(Eval(), Emax.AlgoID.RECURSIVE, 2, 3000) c = e(p.state, ) self.assertIsInstance(c, (int, ))