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
pythonL, S = input().split() L = int(L) max_captured = 0 for i in range(L): if S[i] != '.': continue new_s = S[:i] + 'W' + S[i+1:] chains = [] n = len(new_s) j = 0 while j < n: if new_s[j] in ('B', 'W'): color = new_s[j] start = j while j < n and new_s[j] == color: j += 1 end = j - 1 left = new_s[start - 1] if start > 0 else None right = new_s[end + 1] if end < n - 1 else None chains.append({'color': color, 'start': start, 'end': end, 'left': left, 'right': right}) else: j += 1 # Check if any white chain is surrounded by B valid = True for chain in chains: if chain['color'] == 'W' and chain['left'] == 'B' and chain['right'] == 'B': valid = False break if not valid: continue # Calculate captured black stones captured = 0 for chain in chains: if chain['color'] == 'B' and chain['left'] == 'W' and chain['right'] == 'W': captured += (chain['end'] - chain['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.