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() max_captured = 0 for i in range(L): if S[i] != '.': continue s_new = S[:i] + 'W' + S[i+1:] chains = [] n = L if n == 0: chains = [] else: current_char = s_new[0] start = 0 for j in range(1, n): if s_new[j] != current_char: chains.append((start, j-1, current_char)) current_char = s_new[j] start = j chains.append((start, n-1, current_char)) invalid = False for (s, e, color) in chains: if color == 'W': left = s_new[s-1] if s > 0 else None right = s_new[e+1] if e < n-1 else None if left == 'B' and right == 'B': invalid = True break if invalid: continue captured = 0 for (s, e, color) in chains: if color == 'B': left = s_new[s-1] if s > 0 else None right = s_new[e+1] if e < n-1 else None if left == 'W' and right == 'W': captured += (e - s + 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.