DO-41 [Refactor] 무승부 관련 코드 리팩토링

WIN_COUNT, MinCountForDrawCheck를 Constants로 옮김
최소 착수 값 위치를 조정
This commit is contained in:
Lim0_C 2025-03-21 09:42:45 +09:00
parent 5b1ddd7a95
commit 31b2ebee9f
3 changed files with 66 additions and 15 deletions

View File

@ -6020,6 +6020,50 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 9726acf6f82a3644ba31eda5ef496991, type: 3} m_Script: {fileID: 11500000, guid: 9726acf6f82a3644ba31eda5ef496991, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!1 &820078853
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 820078855}
- component: {fileID: 820078854}
m_Layer: 0
m_Name: OmokAI
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &820078854
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 820078853}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 576baa0fe98d40608bf48109ba5ed788, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &820078855
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 820078853}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 540, y: 1760, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &831992430 --- !u!1001 &831992430
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -17550,3 +17594,4 @@ SceneRoots:
- {fileID: 307507522} - {fileID: 307507522}
- {fileID: 1632066875} - {fileID: 1632066875}
- {fileID: 1118625358} - {fileID: 1118625358}
- {fileID: 820078855}

View File

@ -4,4 +4,7 @@
public const string GameServerURL = "ws://localhost:3000"; public const string GameServerURL = "ws://localhost:3000";
public const int BoardSize = 15; public const int BoardSize = 15;
public const int ReplayMaxRecordSize = 10; public const int ReplayMaxRecordSize = 10;
public const int WIN_COUNT = 5;
//무승부 확인을 위한 최소 착수 수
public const int MinCountForDrawCheck = 150;
} }

View File

@ -24,17 +24,23 @@ public abstract class BasePlayerState
} }
else else
{ {
if (gameLogic.CheckGameDraw(gameLogic.GetBoard())) if (gameLogic.TotalStoneCounter >= Constants.MinCountForDrawCheck)
{ {
GameManager.Instance.panelManager.OpenConfirmPanel($"Game Over: Draw",() =>{}); if (gameLogic.CheckGameDraw())
gameLogic.EndGame(); {
GameManager.Instance.panelManager.OpenConfirmPanel($"Game Over: Draw",() =>{});
gameLogic.EndGame();
}
else
{
HandleNextTurn(gameLogic);
}
} }
else else
{ {
HandleNextTurn(gameLogic); HandleNextTurn(gameLogic);
} }
} }
} }
} }
@ -145,7 +151,7 @@ public class GameLogic : MonoBehaviour
public Enums.PlayerType currentTurn; public Enums.PlayerType currentTurn;
public Enums.GameType gameType; public Enums.GameType gameType;
//총 착수된 돌 카운터 //총 착수된 돌 카운터
private int _totalStoneCounter = 0; public int _totalStoneCounter;
public int TotalStoneCounter{get{return _totalStoneCounter;}} public int TotalStoneCounter{get{return _totalStoneCounter;}}
public BasePlayerState firstPlayerState; public BasePlayerState firstPlayerState;
@ -154,9 +160,6 @@ public class GameLogic : MonoBehaviour
//타이머 //타이머
public FioTimer fioTimer; public FioTimer fioTimer;
private const int WIN_COUNT = 5;
//무승부 확인을 위한 최소 착수 수
private const int MinCountForDrawCheck = 150;
//선택된 좌표 //선택된 좌표
public int selectedRow; public int selectedRow;
public int selectedCol; public int selectedCol;
@ -186,6 +189,7 @@ public class GameLogic : MonoBehaviour
_board = new Enums.PlayerType[15, 15]; _board = new Enums.PlayerType[15, 15];
this.stoneController = stoneController; this.stoneController = stoneController;
this.gameType = gameType; this.gameType = gameType;
_totalStoneCounter = 0;
selectedRow = -1; selectedRow = -1;
selectedCol = -1; selectedCol = -1;
@ -354,7 +358,7 @@ public class GameLogic : MonoBehaviour
var (count, _) = CountStones(_board, row, col, dir, player); var (count, _) = CountStones(_board, row, col, dir, player);
// 자기 자신 포함하여 5개 이상일 시 true 반환 // 자기 자신 포함하여 5개 이상일 시 true 반환
if (count + 1 >= WIN_COUNT) if (count + 1 >= Constants.WIN_COUNT)
return true; return true;
} }
@ -405,12 +409,11 @@ public class GameLogic : MonoBehaviour
return _board; return _board;
} }
//무승부 확인 //무승부 확인
public bool CheckGameDraw(Enums.PlayerType[,] board) public bool CheckGameDraw()
{ {
if (_totalStoneCounter < MinCountForDrawCheck) return false; //최소 착수 수보다 작으면 false 리턴 if (CheckIsFull(_board)) return true; // 빈 칸이 없으면 무승부
if (CheckIsFull(board)) return true; // 빈 칸이 없으면 무승부 bool playerAHasChance = CheckFiveChance(_board, Enums.PlayerType.PlayerA);
bool playerAHasChance = CheckFiveChance(board, Enums.PlayerType.PlayerA); bool playerBHasChance = CheckFiveChance(_board, Enums.PlayerType.PlayerB);
bool playerBHasChance = CheckFiveChance(board, Enums.PlayerType.PlayerB);
return !(playerAHasChance || playerBHasChance); // 둘 다 기회가 없으면 무승부 return !(playerAHasChance || playerBHasChance); // 둘 다 기회가 없으면 무승부
} }
@ -430,7 +433,7 @@ public class GameLogic : MonoBehaviour
var (count, _) = CountStones(tempBoard, row, col, dir, player); var (count, _) = CountStones(tempBoard, row, col, dir, player);
// 자기 자신 포함하여 5개 이상일 시 true 반환 // 자기 자신 포함하여 5개 이상일 시 true 반환
if (count + 1 >= WIN_COUNT) return true; if (count + 1 >= Constants.WIN_COUNT) return true;
} }
} }
} }