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 s_list = list(S) s_list[i] = 'W' s_prime = ''.join(s_list) # Find the white chain including the new 'W' left = i while left >= 0 and s_prime[left] == 'W': left -= 1 left += 1 right = i while right < L and s_prime[right] == 'W': right += 1 right -= 1 # Check if the white chain is surrounded by B left_neighbor = left - 1 right_neighbor = right + 1 left_ok = left_neighbor >= 0 and s_prime[left_neighbor] == 'B' right_ok = right_neighbor < L and s_prime[right_neighbor] == 'B' if left_ok and right_ok: continue # invalid move # Calculate captured black stones captured = 0 current = 0 while current < L: if s_prime[current] != 'B': current += 1 continue start = current while current < L and s_prime[current] == 'B': current += 1 end = current - 1 # Check surroundings for the black chain l_side = start - 1 r_side = end + 1 left_w = l_side >= 0 and s_prime[l_side] == 'W' right_w = r_side < L and s_prime[r_side] == 'W' if left_w and right_w: captured += (end - 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.