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) if n == 0: return [] current_color = s[0] start = 0 for i in range(1, n): if s[i] == current_color: continue chains.append((current_color, start, i-1)) current_color = s[i] start = i chains.append((current_color, start, n-1)) return chains 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) chains = get_chains(t_str) # Check if any white chain is surrounded by B valid = True for color, start, end in chains: if color == 'W': left_ok = False if start > 0: left_ok = t_str[start-1] == 'B' right_ok = False if end < L - 1: right_ok = t_str[end+1] == 'B' if left_ok and right_ok: valid = False break if not valid: continue # Calculate captured black stones captured = 0 for color, start, end in chains: if color == 'B': left_ok = False if start > 0: left_ok = t_str[start-1] == 'W' right_ok = False if end < L - 1: right_ok = t_str[end+1] == 'W' if left_ok and right_ok: 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.