Problem Statement Recently, AIs which play Go (a traditional board game) are well…
- User
Problem Statement
Recently, AIs which play Go (a traditional board game) are well investigated. Your friend Hikaru is planning to develop a new awesome Go AI named Sai and promote it to company F or company G in the future. As a first step, Hikaru has decided to develop an AI for 1D-Go, a restricted version of the original Go.
In both of the original Go and 1D-Go, capturing stones is an important strategy. Hikaru asked you to implement one of the functions of capturing.
In 1D-Go, the game board consists of grids lie in a row. A state of 1D-go is described by a string of length . The -th character of describes the -th grid as the following:
Assistant
def get_chains(s): chains = [] n = len(s) i = 0 while i < n: current_char = s[i] start = i while i < n and s[i] == current_char: i += 1 end = i - 1 chains.append((start, end, current_char)) return chains L, S = input().split() L = int(L) max_captured = 0 for i in range(L): if S[i] != '.': continue s_list = list(S) s_list[i] = 'W' # Find the W chain after placing at i start = i while start > 0 and s_list[start - 1] == 'W': start -= 1 end = i while end < L - 1 and s_list[end + 1] == 'W': end += 1 # Check if surrounded by B on both ends left_ok = (start > 0 and s_list[start - 1] == 'B') right_ok = (end < L - 1 and s_list[end + 1] == 'B') if left_ok and right_ok: continue # invalid move # Check captured B stones s_new = ''.join(s_list) chains = get_chains(s_new) current_sum = 0 for j in range(len(chains)): c_start, c_end, color = chains[j] if color != 'B': continue prev_color = chains[j-1][2] if j > 0 else None next_color = chains[j+1][2] if j < len(chains)-1 else None if prev_color == 'W' and next_color == 'W': current_sum += (c_end - c_start + 1) if current_sum > max_captured: max_captured = current_sum print(max_captured)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.