def select_move(self, game_state): """ 眼をつぶさないように,あとは禁じ手にならなければランダム. 考えうる限り最弱のボット,30級程度 """ candidates = [] for r in range(1, game_state.board.num_rows + 1): for c in range(1, game_state.board.num_cols + 1): candidate = Point(row=r, col=c) # 自殺手,劫なら次の手の候補ではない if not game_state.is_valid_move(Move.play(candidate)): continue # 眼になっているところなら次の手の候補ではない if is_point_an_eye(game_state.board, candidate, game_state.next_player): continue # 候補として追加 candidates.append(candidate) # 打てるところが無ければパス if not candidates: return Move.pass_turn() move = Move.play(random.choice(candidates)) return move
def select_move(self, game_state): candidates = [] for r in range(1, game_state.board.num_rows + 1): for c in range(1, game_state.board.num_cols + 1): candidate = Point(row=r, col=c) if game_state.is_valid_move(Move.play(candidate)) and \ not is_point_an_eye(game_state.board, candidate, game_state.next_player): candidates.append(candidate) if not candidates: return Move.pass_turn() return Move.play(random.choice(candidates))
def select_move(self, game_state): """Choose a random valid move that preserves our own eyes.""" candidates = [] for r in range(1, game_state.board.num_rows + 1): for c in range(1, game_state.board.num_cols + 1): candidate = Point(row=r, col=c) if (game_state.is_valid_move(Move.play(candidate)) and not is_point_an_eye(game_state.board, candidate, game_state.next_player)): candidates.append(candidate) if not candidates: return Move.pass_turn() return Move.play(random.choice(candidates))
def select_move(self, game_state): # Choose a random valid move that preserves our eyes candidates = [] for r in range(1, game_state.board.num_rows + 1): for c in range(1, game_state.board.num_cols + 1): candidate = Point(row=r, col=c) # If a point is empty, not a self-capture, doesn't violate ko and preserve eyes if game_state.is_valid_move(Move.play(candidate)) and \ not is_point_an_eye(game_state.board,candidate,game_state.next_player): candidates.append(candidate) # No valid moves then pass if not candidates: return Move.pass_turn() # Play a random move from the candidates return Move.play(random.choice(candidates))
def select_move(self, game_state): # choose a move that preserves own eyes dim = (game_state.board.num_rows, game_state.board.num_cols) if dim != self.dim: self._update_cache(dim) idx = np.arange(len(self.point_cache)) np.random.shuffle(idx) for i in idx: p = self.point_cache[i] if game_state.is_valid_move(Move.play(p)) and \ not is_point_an_eye(game_state.board, p, game_state.next_player): return Move.play(p) return Move.pass_turn() # can't make a move that doesn't ruin own eyes
def select_move(self, game_state): """Choose a random valid move that preserves our own eyes""" # Get points that are a candidate for placing a stone candidates = [] for r in range(1, game_state.board.num_rows + 1): for c in range(1, game_state.board.num_cols + 1): candidate = Point(row = r, col = c) # If a point within the board is a valid move, save it as a # candidate if game_state.is_valid_move(Move.play(candidate)) and \ not is_point_an_eye(game_state.board, candidate, game_state.next_player): candidates.append(candidate) # If there are no candidates, pass if not candidates: return Move.pass_turn() # Else choose randomly among all the candidate return Move.play(random.choice(candidates))