Ejemplo n.º 1
0
 def expand(self):
     # print("------------------ EXPAND ------------------")
     actions_total_score = Helpers.actions_score(self.simulations)
     # print(f'Node probable actions score: {actions_total_score}')
     # print(f'{len(self.simulations)} actions simulated, building nodes...')
     for action in self.simulations:
         action_player_state, action_opponent_state = action.build_states(
             self.player_state, self.opponent_state)
         child = MCTNode(
             action_player_state, action_opponent_state, 
             action.piece_id, action.action_queue,
             not self.opponent_playing, self, Helpers.calculate_probability(
                 action.distance_score, actions_total_score, 
                 self.opponent_playing
             )
         )
         self.children[child.id] = child
Ejemplo n.º 2
0
 def initial_expansion(self):
     print("------------------ INITIAL EXPANSION ------------------")
     for key, value in self.player_id_table.items():
         self.simulate(key, value, value)
     actions_total_score = Helpers.actions_score(self.simulations)
     print(f'Node probable actions score: {actions_total_score}')
     print(f'{len(self.simulations)} actions simulated, building nodes...')
     for action in self.simulations:
         action_player_state, action_opponent_state = action.build_states(
             self.player_state, self.opponent_state)
         child = MCTNode(
             action_player_state, action_opponent_state, 
             action.piece_id, action.action_queue,
             not self.opponent_playing, self, Helpers.calculate_probability(
                 action.distance_score, actions_total_score, 
                 not self.opponent_playing
             )
         )
         self.children[child.id] = child
         # print(f'Node prior probability: {child.probability * 100}%')
     print("------------------ EXPANSION COMPLETE ------------------")