From d5fdd72ce816a3675b9556ff5e85d026a55a9936 Mon Sep 17 00:00:00 2001 From: fiore Date: Thu, 20 Mar 2025 15:09:06 +0900 Subject: [PATCH] =?UTF-8?q?DO-31=20Debug:=20=EA=B8=88=EC=88=98=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=EB=AC=B8=EC=A0=9C=20=ED=99=95=EC=9D=B8=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Script/Renju/RenjuDoubleFourDetector.cs | 6 +- .../Renju/RenjuDoubleFourDetector.cs.meta | 14 ++- .../Script/Renju/RenjuDoubleThreeDetector.cs | 9 +- .../Renju/RenjuForbiddenMoveDetector.cs | 100 +++++++++++++----- .../Renju/RenjuForbiddenMoveDetector.cs.meta | 14 ++- 5 files changed, 108 insertions(+), 35 deletions(-) diff --git a/Assets/Script/Renju/RenjuDoubleFourDetector.cs b/Assets/Script/Renju/RenjuDoubleFourDetector.cs index 9f38dce..43a3ad3 100644 --- a/Assets/Script/Renju/RenjuDoubleFourDetector.cs +++ b/Assets/Script/Renju/RenjuDoubleFourDetector.cs @@ -133,7 +133,7 @@ public class RenjuDoubleFourDetector: ForbiddenDetectorBase } else { - linePattern[centerIndex + i] = Space; // 범위 밖은 빈칸으로 처리 + linePattern[centerIndex + i] = White; // 범위 밖은 백돌로 처리 } } @@ -149,7 +149,7 @@ public class RenjuDoubleFourDetector: ForbiddenDetectorBase } else { - linePattern[centerIndex - i] = Space; // 범위 밖은 빈칸으로 처리 + linePattern[centerIndex - i] = White; // 범위 밖은 백돌로 처리 } } @@ -178,7 +178,7 @@ public class RenjuDoubleFourDetector: ForbiddenDetectorBase } } - // 정확히 4개의 돌이 있고, 1개의 빈칸이 있으면 4로 판정 + // 4개의 돌이 있고, 1개의 빈칸이 있으면 4로 판정 // (현재 위치는 흑으로 이미 설정되어 있음) if (stoneCount == 4) { diff --git a/Assets/Script/Renju/RenjuDoubleFourDetector.cs.meta b/Assets/Script/Renju/RenjuDoubleFourDetector.cs.meta index abc7cef..54a3220 100644 --- a/Assets/Script/Renju/RenjuDoubleFourDetector.cs.meta +++ b/Assets/Script/Renju/RenjuDoubleFourDetector.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 -guid: 0daf1f2b8cbe4b19adc0e42db7a15991 -timeCreated: 1742270734 \ No newline at end of file +fileFormatVersion: 2 +guid: f997e95272e950240a6e9e2f8a99fdfa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Script/Renju/RenjuDoubleThreeDetector.cs b/Assets/Script/Renju/RenjuDoubleThreeDetector.cs index 02c0ee1..5a7b5d1 100644 --- a/Assets/Script/Renju/RenjuDoubleThreeDetector.cs +++ b/Assets/Script/Renju/RenjuDoubleThreeDetector.cs @@ -18,13 +18,13 @@ public class RenjuDoubleThreeDetector: ForbiddenDetectorBase // 쌍삼 검사 bool isDoubleThree = CheckDoubleThree(board, row, col); - // 쌍삼으로 판정된 경우 4-3 상황인지 추가 검사 + // 쌍삼으로 판정된 경우 if (isDoubleThree) { // 4가 만들어지는지 확인 bool hasFour = CheckForFour(board, row, col); - // 4-3 상황이면 금수에서 제외 + // 4-3 상황 if (hasFour) { isDoubleThree = false; @@ -37,6 +37,8 @@ public class RenjuDoubleThreeDetector: ForbiddenDetectorBase return isDoubleThree; } + + /// /// 쌍삼(3-3) 여부를 검사합니다. /// @@ -56,6 +58,7 @@ public class RenjuDoubleThreeDetector: ForbiddenDetectorBase openThreeCount++; // 이미 열린 3이 2개 이상 발견되면 쌍삼으로 판정 + // TODO : 44를 만들 수 있는가?? if (openThreeCount >= 2) { return true; @@ -119,9 +122,11 @@ public class RenjuDoubleThreeDetector: ForbiddenDetectorBase /// private bool CheckForOpenThree(Enums.PlayerType[] linePattern, int centerIndex) { + // 둘다 아니면 열린 3이 아님 return CheckConsecutiveOpenThree(linePattern, centerIndex) || // 연속된 열린 3 확인 CheckGappedOpenThree(linePattern, centerIndex); // 한 칸 떨어진 열린 3 확인 + // TODO : 한칸 떨어진 열린 3, 여기서 장목이 되는지 체크해서 배제 해야함 } /// diff --git a/Assets/Script/Renju/RenjuForbiddenMoveDetector.cs b/Assets/Script/Renju/RenjuForbiddenMoveDetector.cs index 8fe5421..995bc9b 100644 --- a/Assets/Script/Renju/RenjuForbiddenMoveDetector.cs +++ b/Assets/Script/Renju/RenjuForbiddenMoveDetector.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Text; using UnityEngine; @@ -16,19 +17,19 @@ public class RenjuForbiddenMoveDetector : ForbiddenDetectorBase /// 금수 좌표를 담은 리스트 public List RenjuForbiddenMove(Enums.PlayerType[,] board) { - var tempBoard = (Enums.PlayerType[,])board.Clone(); var forbiddenCount = 0; List forbiddenMoves = new(); + List tempForbiddenMoves = new(); for (int row = 0; row < BoardSize; row++) { for (int col = 0; col < BoardSize; col++) { // ** 비어 있지 않으면 검사할 필요 없음 ** - if (!IsEmptyPosition(tempBoard, row, col)) continue; + if (!IsEmptyPosition(board, row, col)) continue; // 장목 검사 - if (_overlineDetactor.IsOverline(tempBoard, row, col)) + if (_overlineDetactor.IsOverline(board, row, col)) { forbiddenCount++; Debug.Log("장목 금수 좌표 X축 : " + row + ", Y축 : " + col); @@ -37,7 +38,7 @@ public class RenjuForbiddenMoveDetector : ForbiddenDetectorBase } // 4-4 검사 - if (_doubleFourDetactor.IsDoubleFour(tempBoard, row, col)) + if (_doubleFourDetactor.IsDoubleFour(board, row, col)) { forbiddenCount++; Debug.Log("사사 금수 좌표 X축 : " + row + ", Y축 : " + col); @@ -45,40 +46,91 @@ public class RenjuForbiddenMoveDetector : ForbiddenDetectorBase continue; } - if(forbiddenCount >1) continue; + if(forbiddenCount > 0) continue; // 3-3 검사 - if (_doubleThreeDetector.IsDoubleThree(tempBoard, row, col)) + if (_doubleThreeDetector.IsDoubleThree(board, row, col)) { - if (CheckFakeForbiddenMove(tempBoard, row, col)) - { - Debug.Log("삼삼 금수 좌표 X축 : " + row + ", Y축 : " + col); - forbiddenMoves.Add(new Vector2Int(row, col)); - } - + tempForbiddenMoves.Add(new Vector2Int(row, col)); + // if (!SimulateDoubleFour(tempBoard)) + // { + // Debug.Log("삼삼 금수 좌표 X축 : " + row + ", Y축 : " + col); + // forbiddenMoves.Add(new Vector2Int(row, col)); + // } } } } + foreach (var pos in tempForbiddenMoves) + { + board[pos.x, pos.y] = Black; + if (!SimulateDoubleFour(board)&& !SimulateOverline(board)) + { + Debug.Log("X: "+pos.x + "Y: "+ pos.y); + forbiddenMoves.Add(new Vector2Int(pos.x, pos.y)); + } + } + + + Debug.Log(DebugBoard(board)); return forbiddenMoves; } - private bool CheckFakeForbiddenMove(Enums.PlayerType[,] board, int row, int col) + + + private bool SimulateDoubleFour(Enums.PlayerType[,] board) { - var tempBoard = (Enums.PlayerType[,])board.Clone(); - tempBoard[row, col] = Black; - - for (int newRow = 0; newRow < BoardSize; newRow++) + for (int row = 0; row < BoardSize; row++) { - for (int newCol = 0; newCol < BoardSize; newCol++) + for (int col = 0; col < BoardSize; col++) { - // ** 비어 있지 않으면 검사할 필요 없음 ** - if (!IsEmptyPosition(tempBoard, newRow, newCol)) continue; - - return _overlineDetactor.IsOverline(tempBoard, newRow, newCol) || - _doubleFourDetactor.IsDoubleFour(tempBoard, newRow, newCol); + if (_doubleFourDetactor.IsDoubleFour(board, row, col)) + return true; } } return false; } -} \ No newline at end of file + + private bool SimulateOverline(Enums.PlayerType[,] board) + { + for (int row = 0; row < BoardSize; row++) + { + for (int col = 0; col < BoardSize; col++) + { + if (_overlineDetactor.IsOverline(board, row, col)) + { + return true; + } + } + } + return false; + } + + /// + /// 보드 상태를 시각적으로 출력하는 디버깅 함수 + /// + /// 현재 보드 상태 + /// 보드의 시각적 표현 문자열 + private string DebugBoard(Enums.PlayerType[,] board) + { + StringBuilder sb = new StringBuilder(); + + for (int row = 0; row < BoardSize; row++) + { + for (int col = 0; col < BoardSize; col++) + { + sb.Append(board[row, col] switch + { + Enums.PlayerType.None => "□", + Enums.PlayerType.PlayerA => "●", + Enums.PlayerType.PlayerB => "○", + _ => "?" + }); + } + sb.AppendLine(); // 줄바꿈 추가 + } + + return sb.ToString(); + } +} + diff --git a/Assets/Script/Renju/RenjuForbiddenMoveDetector.cs.meta b/Assets/Script/Renju/RenjuForbiddenMoveDetector.cs.meta index 511a9bd..05a239d 100644 --- a/Assets/Script/Renju/RenjuForbiddenMoveDetector.cs.meta +++ b/Assets/Script/Renju/RenjuForbiddenMoveDetector.cs.meta @@ -1,3 +1,11 @@ -fileFormatVersion: 2 -guid: 8618553c3e244abdb040fb7378dd4b65 -timeCreated: 1741939566 \ No newline at end of file +fileFormatVersion: 2 +guid: 4440d621b56f2ce459d819497911892b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: