def expand(self):
     size = int((len(self.state) - 1)**0.5)
     state_manager = StateManager(size, self.state)
     possible_moves = state_manager.get_moves()
     self.children = []
     for move in possible_moves:
         state_manager.make_move(move)
         self.children.append((Node(self,
                                    state_manager.string_representation()),
                               0))  # Visited 0 times
         state_manager.undo_move(move)
 def rollout(self, leaf):
     size = int((len(leaf.state) - 1) ** 0.5)
     leaf_state, first_iteration = StateManager(size, leaf.state), True
     while True:
         if leaf_state.player1_won():
             score = 1.0
             return score
         elif leaf_state.player2_won(): 
             score = -1.0
             return score
         if leaf_state.is_finished():
             print("No winner error")
             quit()
         if first_iteration:
             possible_moves = leaf_state.get_moves()
             move = possible_moves[random.randint(0, len(possible_moves) - 1)]
             first_iteration = False
         else:
             move = leaf_state.convert_to_move(self.nn.get_action(leaf_state.string_representation()))
         leaf_state.make_move(move)