def policy_moves_cmd(self, args): moves = [] probs = [] if self.go_engine.random_simulation: color = self.board.current_player empty_pts = self.board.get_empty_points() legal_pts = [ move for move in empty_pts if self.board.is_legal(move, color) ] probs = [ str(round(1 / len(legal_pts), 3)) for _ in range(len(legal_pts)) ] for mv in legal_pts: coord = point_to_coord(mv, self.board.size) moves.append(format_point(coord).lower()) mv_str = ' '.join(sorted(moves)) prob_str = ' '.join(probs) self.respond(mv_str + " " + prob_str) else: m = PatternUtil.generate_pattern_moves(self.board, self.pattern_table) mvs, vals = PatternUtil.calc_probabilities(m) for mv in mvs: coord = point_to_coord(mv, self.board.size) moves.append(format_point(coord).lower()) sorted_mvs, sorted_vals = (list(i) for i in zip(*sorted(zip(moves, vals)))) probs = [str(round(num, 3)) for num in sorted_vals] mvs_str = ' '.join(sorted_mvs) sorted_vals = ' '.join(probs) self.respond(mvs_str + " " + sorted_vals)
def policy_moves_cmd(self, args): if self.go_engine.random_simulation == True: empties = self.board.get_empty_points() color = self.board.current_player legal_moves = [] for move in empties: if self.board.is_legal(move, color): legal_moves.append(move) gtp_moves = [] probabilities = [] for move in legal_moves: coords = point_to_coord(move, self.board.size) gtp_moves.append(format_point(coords).lower()) probabilities.append(str(round(1 / len(legal_moves), 3))) sorted_moves = ' '.join(sorted(gtp_moves)) probability = ' '.join(probabilities) self.respond(sorted_moves + " " + probability) else: moves, values = PatternUtil.generate_pattern_moves(self.board) new_values = PatternUtil.normalize_val(values) dict = {} #sorted_moves = sorted(moves) new_sorted_values = [] format_moves = [] for move in moves: #new_sorted_values.append(str(round(dict[move], 3))) coords = point_to_coord(move, self.board.size) format_moves.append(format_point(coords).lower()) for i in range(len(format_moves)): dict[format_moves[i]] = new_values[i] sorted_format_moves = sorted(format_moves) for move in sorted_format_moves: new_sorted_values.append(str(round(dict[move], 3))) sorted_moves_str = ' '.join(sorted_format_moves) probability = ' '.join(new_sorted_values) self.respond(sorted_moves_str + " " + probability)