def prior_knowledge_cmd(self, args): ''' ''' # get moves and probs for legal moves using function given in GoBoardUtilGo4, but with pass move moves, probs = GoBoardUtilGo4.generate_moves_with_feature_based_probs( self.board) priorKnowledgeList = GoBoardUtilGo4.prior_knowledge_initialization( moves, probs) color = self.board.current_player response = "" # convert moves from format 9 to a1 for move in priorKnowledgeList: # jank? need to print PASS as Pass if move[0] == 'PASS': move[0] = 'Pass' else: move[0] = GoBoardUtil.format_point( self.board._point_to_coord(move[0])) # sort by winrate, breaking ties alphabetically sortedList = sorted(priorKnowledgeList, key=lambda x: x[0]) sortedList = sorted(sortedList, key=lambda x: x[3], reverse=True) for move in sortedList: response += move[0] + ' ' + str(int( (round(move[1])))) + ' ' + str(int(round((move[2])))) + ' ' self.respond(response)
def expandWithKnowledge(self, board, color): # how do i do initialize root values to be the sum of its children, need to do moves, probs = GoBoardUtilGo4.generate_moves_with_feature_based_probs( board) maxProb = max(probs) passProb = probs[-1] # move, wins, simulations priorKnowledgeList = [] # populate priorKnowledgeList to check for moves and children for move in moves: # check for pass move if move == 'PASS': simulation = 10 * (passProb / maxProb) wins = (((passProb / maxProb) / 2) + 0.5) * simulation priorKnowledgeList.append([move, wins, simulation]) # move is not pass else: simulation = 10 * (probs[move] / maxProb) wins = (((probs[move] / maxProb) / 2) + 0.5) * simulation priorKnowledgeList.append([move, wins, simulation]) empty_points = board.get_empty_points() for move in empty_points: # move needs to be a legal one as well before init if move not in self._children and board.check_legal( move, color) and not board.is_eye(move, color): self._children[move] = TreeNode(self) self._children[move]._move = move for point in priorKnowledgeList: # need to replace 0's with values if point[0] == move: self._children[move]._black_wins = point[1] self._children[move]._n_visits = point[2] self._children[PASS] = TreeNode(self) self._children[PASS]._move = PASS self._children[PASS]._black_wins = priorKnowledgeList[-1][1] self._children[PASS]._n_visits = priorKnowledgeList[-1][2] self._expanded = True