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
L, S = input().split() L = int(L) max_captured = 0 for i in range(L): if S[i] != '.': continue T = list(S) T[i] = 'W' T_str = ''.join(T) # Find the W chain including the new stone start = i while start > 0 and T_str[start - 1] == 'W': start -= 1 end = i while end < L - 1 and T_str[end + 1] == 'W': end += 1 # Check if the W chain is surrounded by B on both ends left_B = start > 0 and T_str[start - 1] == 'B' right_B = end < L - 1 and T_str[end + 1] == 'B' if left_B and right_B: continue # Invalid move # Calculate captured B stones captured = 0 current = 0 while current < L: if T_str[current] != 'B': current += 1 continue b_start = current while current < L and T_str[current] == 'B': current += 1 b_end = current - 1 left = b_start - 1 right = b_end + 1 left_W = left >= 0 and T_str[left] == 'W' right_W = right < L and T_str[right] == 'W' if left_W and right_W: captured += (b_end - b_start + 1) if captured > max_captured: max_captured = captured 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.