public class RenjuOverlineDetector : ForbiddenDetectorBase { /// /// 장목 여부를 검사합니다. /// /// 현재 보드 상태 /// 행 (y 좌표) /// 열 (x 좌표) /// 장목이면 true, 아니면 false public bool IsOverline(Enums.PlayerType[,] board, int row, int col) { // 임시로 돌 놓기 board[row, col] = Black; // 장목 검사 bool isOverline = CheckOverline(board, row, col); board[row, col] = Space; return isOverline; } /// /// 장목(6목 이상) 여부를 검사합니다. /// private bool CheckOverline(Enums.PlayerType[,] board, int row, int col) { // 4개의 방향 쌍에 대해 검사 for (int i = 0; i < 4; i++) { int dir1 = DirectionPairs[i, 0]; int dir2 = DirectionPairs[i, 1]; // 해당 방향 쌍에서 연속된 돌의 총 개수 계산 int count = CountConsecutiveStones(board, row, col, dir1, dir2); // 6목 이상이면 장목 if (count >= 6) { return true; } } return false; } /// /// 특정 방향 쌍에서 연속된 돌의 개수를 계산합니다. /// /// 현재 보드 상태 /// 시작 행 /// 시작 열 /// 첫 번째 방향 인덱스 /// 두 번째(반대) 방향 인덱스 /// 연속된 돌의 총 개수 private int CountConsecutiveStones(Enums.PlayerType[,] board, int row, int col, int dir1, int dir2) { int count = 1; // 현재 위치의 돌 포함 // 첫 번째 방향으로 연속된 돌 확인 count += CountInDirection(board, row, col, dir1); // 두 번째(반대) 방향으로 연속된 돌 확인 count += CountInDirection(board, row, col, dir2); return count; } /// /// 특정 방향으로의 연속된 돌 개수를 계산합니다. /// /// 현재 보드 상태 /// 시작 행 /// 시작 열 /// 방향 인덱스 /// 해당 방향의 연속된 돌 개수 private int CountInDirection(Enums.PlayerType[,] board, int startRow, int startCol, int dirIndex) { int count = 0; int dRow = Directions[dirIndex, 0]; int dCol = Directions[dirIndex, 1]; for (int i = 1; i < BoardSize; i++) { int newRow = startRow + dRow * i; int newCol = startCol + dCol * i; if (IsInBounds(newRow, newCol) && board[newRow, newCol] == Black) { count++; } else { break; } } return count; } }