Ejemplo n.º 1
0
    def think(self, status):
        """Chooses an action, using paranoid.

        Arguments:
            status (Status): the game status.

        Returns:
            Action: the chosen action.
        """

        def successor(status):
            actions = list(Action)
            shuffle(actions)
            children = []
            for action in actions:
                next_status = simulate(status, action)
                children.append((next_status, action))
            return children

        def payoff(status):
            return self.heuristic.hero_heuristic(status, self.hero_id)

        happyness, actions = paranoid(
            status,
            successor,
            payoff,
            5,  # max_depth
            self.hero_id,
            self.hero_id,
            4
        )

        action = actions[0]

        return action
Ejemplo n.º 2
0
 def test_maximum_depth_1(self):
     payoff = lambda status: self.full_payoff(status)[0]
     actions = paranoid(0, self.succ, payoff, 1, 0, 0, 3)
     self.assertEqual(actions, (3, ['c']))
Ejemplo n.º 3
0
 def test_different_root_and_paranoid_player(self):
     payoff = lambda status: self.full_payoff(status)[1]
     actions = paranoid(2, self.succ, payoff, 999, 1, 1, 3)
     self.assertEqual(actions, (1, ['d']))
Ejemplo n.º 4
0
 def test_on_leaf(self):
     payoff = lambda status: self.full_payoff(status)[0]
     actions = paranoid(10, self.succ, payoff, 999, 0, 0, 3)
     self.assertEqual(actions, (0, []))
Ejemplo n.º 5
0
 def test_different_root(self):
     payoff = lambda status: self.full_payoff(status)[0]
     actions = paranoid(2, self.succ, payoff, 999, 0, 0, 3)
     self.assertEqual(actions, (7, ['b']))
Ejemplo n.º 6
0
 def test_different_current_player(self):
     payoff = lambda status: self.full_payoff(status)[0]
     actions = paranoid(0, self.succ, payoff, 999, 0, 1, 3)
     self.assertEqual(actions, (-1, ['c', 'd']))
Ejemplo n.º 7
0
 def test_simple(self):
     payoff = lambda status: self.full_payoff(status)[0]
     actions = paranoid(0, self.succ, payoff, 999, 0, 0, 3)
     self.assertEqual(actions, (1, ['b', 'a']))