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
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']))
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']))
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, []))
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']))
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']))
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']))