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 T = list(S) T[i] = 'W' T = ''.join(T) # Find the boundaries of the W chain after placing at i l = i while l > 0 and T[l-1] == 'W': l -= 1 r = i while r < L-1 and T[r+1] == 'W': r += 1 # Check if the new W chain is surrounded by B on both ends left_B = False if l > 0 and T[l-1] == 'B': left_B = True right_B = False if r < L-1 and T[r+1] == 'B': right_B = True if left_B and right_B: continue # Invalid move # Calculate captured black stones captured = 0 pos = 0 while pos < L: if T[pos] != 'B': pos += 1 continue a = pos while pos < L and T[pos] == 'B': pos += 1 b = pos - 1 left_ok = (a > 0 and T[a-1] == 'W') or (a == 0) right_ok = (b < L-1 and T[b+1] == 'W') or (b == L-1) if not left_ok and not right_ok: # Both sides are W left_neighbor = a - 1 right_neighbor = b + 1 if (left_neighbor >= 0 and T[left_neighbor] == 'W') and (right_neighbor < L and T[right_neighbor] == 'W'): captured += (b - a + 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.