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
# Read input L, S = input().split() L = int(L) max_captured = 0 for i in range(L): if S[i] != '.': continue # Create the new state after placing 'W' at position i T = list(S) T[i] = 'W' T_str = ''.join(T) # Find the boundaries of the white chain including i left = i while left > 0 and T_str[left-1] == 'W': left -= 1 right = i while right < L-1 and T_str[right+1] == 'W': right += 1 # Check if the white chain is surrounded by B on both sides left_bound = left - 1 right_bound = right + 1 left_B = left_bound >= 0 and T_str[left_bound] == 'B' right_B = right_bound < L and T_str[right_bound] == 'B' if left_B and right_B: continue # Invalid move # Calculate captured black stones captured = 0 current = 0 while current < L: if T_str[current] == 'B': start = current while current < L and T_str[current] == 'B': current += 1 end = current - 1 # Check surroundings left_side = start - 1 right_side = end + 1 left_W = left_side >= 0 and T_str[left_side] == 'W' right_W = right_side < L and T_str[right_side] == 'W' if left_W and right_W: captured += (end - start + 1) else: current += 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.