0, 1, 2로 이루어진 19x19 오목판
첫 번째 줄에는 5개가 연속된 숫자 혹은 0을 출력
두 번째 줄에는 연속된 5개 오목알 중 가장 왼쪽에 위치한 오목알의 좌표
line_dx = [-1, 0, 1, 0]
line_dy = [0, -1, 0, 1]
opp_dx = [-1, -1, 1, 1]
opp_dy = [-1, 1, -1, 1]
...
for idx in range(4):
if cons_check(board, [line_dy[idx], line_dx[idx]], color, [y, x]):
ans[0], ans[2] = color, x
dx, dy = line_dx[idx], line_dy[idx]
end = True
break
if cons_check(board, [opp_dy[idx], opp_dx[idx]], color, [y, x]):
ans[0], ans[2] = color, x
dx, dy = opp_dx[idx], opp_dy[idx]
end = True
break
def cons_check(board, way, color, start):
_start = copy.deepcopy(start)
_color = color
dx = way[1]
dy = way[0]
_flag = 1
while True:
if _start[0]+dy >= 0 and _start[0]+dy < 19 and _start[1]+dx >= 0 and _start[1]+dx < 19:
_start[0] += dy
_start[1] += dx
if board[_start[0]][_start[1]] == _color: _flag += 1
else: break
else: break
if _flag == 5 and opp_check(board, way, color, start): return True
else: return False
def opp_check(board, way, color, start):
_start = copy.deepcopy(start)
_color = color
if way[0] == 1: dy = -1
elif way[0] == -1: dy = 1
else: dy = 0
if way[1] == 1: dx = -1
elif way[1] == -1: dx = 1
else: dx = 0
if _start[0]+dy >= 0 and _start[0]+dy < 19 and _start[1]+dx >= 0 and _start[1]+dx < 19:
_start[0] += dy
_start[1] += dx
else: return True
if board[_start[0]][_start[1]] != _color: return True
else: return False