Exemple #1
0
    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()
Exemple #2
0
 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
Exemple #3
0
 def test_strats(self):
     p = Ply(chance=1)    
     self.assertTrue(p.strategies.actions[0] == Action.ATTACK)
Exemple #4
0
 def test_steps(self):
     p = Ply(chance=1)
     self.assertEqual(p.steps,1)
Exemple #5
0
 def test_state(self):
     p = Ply(chance=1)
     self.assertIsInstance(p.state,(StrategyNode,))
Exemple #6
0
 def test_seed(self):
     p = Ply(chance=1)
     self.assertIsInstance(p.seed,(int,))
Exemple #7
0
 def test_increment(self):
     p = Ply(chance=1)
     self.assertIsInstance(p.increment(0,1), (Ply,))
Exemple #8
0
 def test_expectation(self):
     p = Ply(chance=1)
     self.assertIsInstance(p.expectation,(float,))
Exemple #9
0
 def test_event(self):
     p = Ply(chance=1)
     self.assertIsInstance(p.event,(Ply.Event,))
Exemple #10
0
 def test_board(self):
     p = Ply(chance=1)
     self.assertEqual(p.board[0], Unit.X)
     self.assertEqual(p.board[29], Unit.NONE)
Exemple #11
0
 def test_agent(self):
     p = Ply(chance=1)
     self.assertEqual(p.agent, Unit.X)
Exemple #12
0
 def test_call(self):
     p = Ply(chance=1)
     e = Emax(Eval(), Emax.AlgoID.RECURSIVE, 2, 3000)
     c = e(p.state, )
     self.assertIsInstance(c, (int, ))