Esempio n. 1
0
 def expand(self):
     """Generate children"""
     for action in possible_actions(self.state, player(self.state)):
         new_child = self.new_child(apply_action(self.state, action), self)
         new_child.action = action
         self._children.append(new_child)
     self.is_expanded = True
Esempio n. 2
0
    def greedy_action(self):
        """
        :strategy: Choose the best action without considering opponent moves.
        """
        best_eval, best_action, best_new_action = -inf, None, None

        for action in possible_actions(self.state, self.colour):
            new_state = apply_action(self.state, action)
            new_eval = runner(new_state)[PLAYER_HASH[self.colour]]
            if new_eval > best_eval:
                best_eval = new_eval
                best_action = action
                if Z_hash(new_state) not in self.counts:
                    best_new_action = action
        return best_new_action if not None else best_action
Esempio n. 3
0
 def update(self, colour, action):
     """
     This method is called at the end of every turn (including your player’s
     turns) to inform your player about the most recent, assumedly correct,
     action."""
     self.state = apply_action(self.state, action)
Esempio n. 4
0
 def update(self, colour, action):
     """
     Updates a players action and adds a turn count.
     """
     self.state = apply_action(self.state, action)
     self.counts[Z_hash(self.state)] += 1