def genmove_cmd(self, args): """ Generate a move for the color args[0] in {'b', 'w'}, for the game of gomoku. """ board_color = args[0].lower() color = color_to_int(board_color) movelist, pro = self.policy_moves_cmd("1") if not movelist: self.respond("resign") else: coard = self.board.copy() if self.go_engine.use_ucb: move = runUcb(self.go_engine, coard, 0.4, movelist, coard.current_player) else: RRmoveWins = [] for move in movelist: wins = self.go_engine.simulateMove(coard, move, coard.current_player) RRmoveWins.append(wins) move = select_best_move(self.board, movelist, RRmoveWins) move_coord = point_to_coord(move, self.board.size) move_as_string = format_point(move_coord) if self.board.is_legal(move, color): self.board.play_move(move, color) self.respond(move_as_string.lower()) else: self.respond("resign")
def get_move(board, color, selection_policy, sim_num, get_best): """ Run one-ply MC simulations to get a move to play. """ #cboard = board.copy() emptyPoints = board.get_empty_points() moves = [] for p in emptyPoints: if board.is_legal(p, color): moves.append(p) if not moves: return None moves.append(None) if selection_policy == "ucb": C = 0.4 #sqrt(2) is safe, this is more aggressive return runUcb(board, C, moves, color, sim_num, get_best) else: moveWins = [] for move in moves: wins = simulateMove(board, move, color, sim_num) moveWins.append(wins) if get_best: return select_best_move(board, moves, moveWins) else: return writeMoves(board, moves, moveWins, len(moves)*sim_num)
def get_move(self, board, color): #get All Legal Moves cboard = board.copy() emptyPoints = board.get_empty_points() #List of All Legal Moves moves = [] #Check if Move is Legal #If it is Append it to moves[] Otherwise Ignore it for p in emptyPoints: if board.is_legal(p, color): moves.append(p) if not moves: return None moves.append(None) #implement UCB if self.use_ucb: C = 0.4 #sqrt(2) is safe, this is more aggressive best = runUcb(self, cboard, C, moves, color) return best #Run Round Robin else: RRmoveWins = [] for move in moves: wins = self.simulateMove(self, board, move, color) RRmoveWins.append(wins) writeMoves(cboard, moves, RRmoveWins, self.sim) return select_best_move(board, moves, RRmoveWins)
def get_move(self, board, color): """ Run one-ply MC simulations to get a move to play. """ cboard = board.copy() moves = GoBoardUtil.generate_legal_moves(board, board.current_player) self.best_move = moves[0] if not moves: return None C = 0.4 #sqrt(2) is safe, this is more aggressive best = ucb.runUcb(self, cboard, C, moves, color) return best '''
def get_move(self, board, color, table): """ Run one-ply MC simulations to get a move to play. """ cboard = board.copy() empty_points = board.get_empty_points() moves = [p for p in empty_points if board.is_legal(p, color)] if not moves: return None moves.append(None) if self.use_ucb: C = 0.4 #sqrt(2) is safe, this is more aggressive best = runUcb(self, cboard, C, moves, color, table) return best else: moveWins = [] for move in moves: wins = self.simulateMove(cboard, move, color, table) moveWins.append(wins) return select_best_move(board, moves, moveWins)
def get_move(self, board, toplay): cboard = board.copy() emptyPoints = board.get_empty_points() moves = [] for p in emptyPoints: if board.check_legal(p, toplay): moves.append(p) if not moves: # pass move only, no need to simulate return None moves.append(None) # None for Pass if self.use_ucb == True: C = 0.4 #sqrt(2) is safe, this is more aggressive best = runUcb(self, board, cboard, C, moves, toplay) return best else: moveWins = [] for move in moves: wins = self.simulateMove(board, cboard, move, toplay) moveWins.append(wins) writeMoves(board, moves, moveWins, self.num_simulation) return select_best_move(board, moves, moveWins)
def get_move(self, board, color): #return GoBoardUtil.generate_random_move(board, color, False) #cboard = board.copy() emptyPoints = board.get_empty_points() moves = [] for p in emptyPoints: if board.is_legal(p, color): moves.append(p) if not moves: return None if self.use_ucb: C = 0.4 #sqrt(2) is safe, this is more aggressive best = runUcb(self, board, C, moves, color) return best else: moveWins = [] for move in moves: wins = self.simulateMove(board, move, color) moveWins.append(wins) #writeMoves(cboard, moves, moveWins, self.sim) return select_best_move(board, moves, moveWins)