DO-4 [Style] AI 코드 정리
This commit is contained in:
parent
333b769241
commit
fc321e9cda
File diff suppressed because it is too large
Load Diff
@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: e200b684d5479a643aa06e6361c430c9
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -4798,6 +4798,7 @@ GameObject:
|
|||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 679766978}
|
- component: {fileID: 679766978}
|
||||||
- component: {fileID: 679766977}
|
- component: {fileID: 679766977}
|
||||||
|
- component: {fileID: 679766979}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: GameManager
|
m_Name: GameManager
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@ -4817,16 +4818,8 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 35a4c6d5d3a97b444b968e68ec8bb9f7, type: 3}
|
m_Script: {fileID: 11500000, guid: 35a4c6d5d3a97b444b968e68ec8bb9f7, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
mainPanel: {fileID: 8564394481744056992, guid: e1835a90a4d722a4b99be61179de8789, type: 3}
|
panelManagerPrefab: {fileID: 3475740041361426276, guid: 085ca07ca90c92545b2594bd13412701, type: 3}
|
||||||
signinPanel: {fileID: 925522282249935710, guid: e14c9b2925f0ddb4192af743e5cc166a, type: 3}
|
audioManagerPrefab: {fileID: 2946408323859178723, guid: e829818dce39a5d4383e061111bed871, type: 3}
|
||||||
signupPanel: {fileID: 3181524094944658765, guid: 8827fe7caa3145e40b1369cc42f8697d, type: 3}
|
|
||||||
settingsPanel: {fileID: 2861881646994438329, guid: ea820246b5075c54d9f614291ca41c5d, type: 3}
|
|
||||||
confirmPanel: {fileID: 8145365568262946399, guid: 76f1fe6b5243faf4f9b8caee7312d336, type: 3}
|
|
||||||
rankingPanel: {fileID: 0}
|
|
||||||
shopPanel: {fileID: 0}
|
|
||||||
giboPanel: {fileID: 0}
|
|
||||||
canvas: {fileID: 2704399793934511678}
|
|
||||||
profileSprites: []
|
|
||||||
--- !u!4 &679766978
|
--- !u!4 &679766978
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -4842,6 +4835,102 @@ Transform:
|
|||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!82 &679766979
|
||||||
|
AudioSource:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 679766976}
|
||||||
|
m_Enabled: 1
|
||||||
|
serializedVersion: 4
|
||||||
|
OutputAudioMixerGroup: {fileID: 0}
|
||||||
|
m_audioClip: {fileID: 0}
|
||||||
|
m_PlayOnAwake: 1
|
||||||
|
m_Volume: 1
|
||||||
|
m_Pitch: 1
|
||||||
|
Loop: 0
|
||||||
|
Mute: 0
|
||||||
|
Spatialize: 0
|
||||||
|
SpatializePostEffects: 0
|
||||||
|
Priority: 128
|
||||||
|
DopplerLevel: 1
|
||||||
|
MinDistance: 1
|
||||||
|
MaxDistance: 500
|
||||||
|
Pan2D: 0
|
||||||
|
rolloffMode: 0
|
||||||
|
BypassEffects: 0
|
||||||
|
BypassListenerEffects: 0
|
||||||
|
BypassReverbZones: 0
|
||||||
|
rolloffCustomCurve:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Curve:
|
||||||
|
- serializedVersion: 3
|
||||||
|
time: 0
|
||||||
|
value: 1
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
weightedMode: 0
|
||||||
|
inWeight: 0.33333334
|
||||||
|
outWeight: 0.33333334
|
||||||
|
- serializedVersion: 3
|
||||||
|
time: 1
|
||||||
|
value: 0
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
weightedMode: 0
|
||||||
|
inWeight: 0.33333334
|
||||||
|
outWeight: 0.33333334
|
||||||
|
m_PreInfinity: 2
|
||||||
|
m_PostInfinity: 2
|
||||||
|
m_RotationOrder: 4
|
||||||
|
panLevelCustomCurve:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Curve:
|
||||||
|
- serializedVersion: 3
|
||||||
|
time: 0
|
||||||
|
value: 0
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
weightedMode: 0
|
||||||
|
inWeight: 0.33333334
|
||||||
|
outWeight: 0.33333334
|
||||||
|
m_PreInfinity: 2
|
||||||
|
m_PostInfinity: 2
|
||||||
|
m_RotationOrder: 4
|
||||||
|
spreadCustomCurve:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Curve:
|
||||||
|
- serializedVersion: 3
|
||||||
|
time: 0
|
||||||
|
value: 0
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
weightedMode: 0
|
||||||
|
inWeight: 0.33333334
|
||||||
|
outWeight: 0.33333334
|
||||||
|
m_PreInfinity: 2
|
||||||
|
m_PostInfinity: 2
|
||||||
|
m_RotationOrder: 4
|
||||||
|
reverbZoneMixCustomCurve:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Curve:
|
||||||
|
- serializedVersion: 3
|
||||||
|
time: 0
|
||||||
|
value: 1
|
||||||
|
inSlope: 0
|
||||||
|
outSlope: 0
|
||||||
|
tangentMode: 0
|
||||||
|
weightedMode: 0
|
||||||
|
inWeight: 0.33333334
|
||||||
|
outWeight: 0.33333334
|
||||||
|
m_PreInfinity: 2
|
||||||
|
m_PostInfinity: 2
|
||||||
|
m_RotationOrder: 4
|
||||||
--- !u!1001 &681290285
|
--- !u!1001 &681290285
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -31,7 +31,7 @@ public static class MiniMaxAIController
|
|||||||
public static void SetLevel(int level)
|
public static void SetLevel(int level)
|
||||||
{
|
{
|
||||||
_playerLevel = level;
|
_playerLevel = level;
|
||||||
// 레벨에 따른 실수률? 설정
|
// 레벨에 따른 실수율? 설정
|
||||||
_mistakeMove = GetMistakeProbability(_playerLevel);
|
_mistakeMove = GetMistakeProbability(_playerLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,8 +99,8 @@ public static class MiniMaxAIController
|
|||||||
private static float DoMinimax(Enums.PlayerType[,] board, int depth, bool isMaximizing, float alpha, float beta,
|
private static float DoMinimax(Enums.PlayerType[,] board, int depth, bool isMaximizing, float alpha, float beta,
|
||||||
int recentRow, int recentCol)
|
int recentRow, int recentCol)
|
||||||
{
|
{
|
||||||
if (CheckGameWin(Enums.PlayerType.PlayerA, board, recentRow, recentCol)) return -100 + depth;
|
if (CheckGameWin(Enums.PlayerType.PlayerA, board, recentRow, recentCol, true)) return -100 + depth;
|
||||||
if (CheckGameWin(Enums.PlayerType.PlayerB, board, recentRow, recentCol)) return 100 - depth;
|
if (CheckGameWin(Enums.PlayerType.PlayerB, board, recentRow, recentCol, true)) return 100 - depth;
|
||||||
if (depth == 0) return AIEvaluator.EvaluateBoard(board, _AIPlayerType);
|
if (depth == 0) return AIEvaluator.EvaluateBoard(board, _AIPlayerType);
|
||||||
|
|
||||||
float bestScore = isMaximizing ? float.MinValue : float.MaxValue;
|
float bestScore = isMaximizing ? float.MinValue : float.MaxValue;
|
||||||
@ -154,9 +154,8 @@ public static class MiniMaxAIController
|
|||||||
// score가 높은 순으로 정렬 -> 더 좋은 수 먼저 계산하도록 함
|
// score가 높은 순으로 정렬 -> 더 좋은 수 먼저 계산하도록 함
|
||||||
validMoves.Sort((a, b) => b.Item3.CompareTo(a.Item3));
|
validMoves.Sort((a, b) => b.Item3.CompareTo(a.Item3));
|
||||||
|
|
||||||
// 상위 10-15개만 고려. 일단 15개
|
// 시간 단축을 위해 상위 10-15개만 고려. 일단 15개
|
||||||
return validMoves.Take(15).ToList();
|
return validMoves.Take(15).ToList();
|
||||||
// return validMoves;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool HasNearbyStones(Enums.PlayerType[,] board, int row, int col, int distance = 3)
|
private static bool HasNearbyStones(Enums.PlayerType[,] board, int row, int col, int distance = 3)
|
||||||
@ -249,8 +248,8 @@ public static class MiniMaxAIController
|
|||||||
_spatialStoneCache.Clear();
|
_spatialStoneCache.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 캐시 부분 초기화 (현재 변경된 위치 N에서 반경 5칸만 초기화)
|
// 캐시 부분 초기화 (현재 변경된 위치 N에서 반경 4칸만 초기화)
|
||||||
private static void ClearCachePartial(int centerRow, int centerCol, int radius = 5)
|
private static void ClearCachePartial(int centerRow, int centerCol, int radius = 4)
|
||||||
{
|
{
|
||||||
// 캐시가 비어있으면 아무 작업도 하지 않음
|
// 캐시가 비어있으면 아무 작업도 하지 않음
|
||||||
if (_spatialStoneCache.Count == 0) return;
|
if (_spatialStoneCache.Count == 0) return;
|
||||||
@ -274,7 +273,7 @@ public static class MiniMaxAIController
|
|||||||
// 최근에 둔 돌 위치 기반으로 게임 승리를 판별하는 함수
|
// 최근에 둔 돌 위치 기반으로 게임 승리를 판별하는 함수
|
||||||
// !!!!!!MinimaxAIController 밖의 cs파일은 호출 시 맨 마지막을 false로 지정해야 합니다.!!!!!!
|
// !!!!!!MinimaxAIController 밖의 cs파일은 호출 시 맨 마지막을 false로 지정해야 합니다.!!!!!!
|
||||||
public static bool CheckGameWin(Enums.PlayerType player, Enums.PlayerType[,] board,
|
public static bool CheckGameWin(Enums.PlayerType player, Enums.PlayerType[,] board,
|
||||||
int row, int col, bool isSavedCache = true)
|
int row, int col, bool isSavedCache)
|
||||||
{
|
{
|
||||||
foreach (var dir in _directions)
|
foreach (var dir in _directions)
|
||||||
{
|
{
|
||||||
|
@ -1,84 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using TMPro;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Serialization;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
public class TestGameManager : MonoBehaviour
|
|
||||||
{
|
|
||||||
[SerializeField] private TMP_InputField rowText;
|
|
||||||
[SerializeField] private TMP_InputField colText;
|
|
||||||
[SerializeField] private TMP_Text boardText;
|
|
||||||
|
|
||||||
private Enums.PlayerType[,] _board;
|
|
||||||
|
|
||||||
private void Start()
|
|
||||||
{
|
|
||||||
_board = new Enums.PlayerType[15, 15];
|
|
||||||
MiniMaxAIController.SetLevel(1); // 급수 설정 테스트
|
|
||||||
ResultBoard();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnClickGoButton()
|
|
||||||
{
|
|
||||||
int row = int.Parse(rowText.text);
|
|
||||||
int col = int.Parse(colText.text);
|
|
||||||
|
|
||||||
if (_board[row, col] != Enums.PlayerType.None)
|
|
||||||
{
|
|
||||||
Debug.Log("중복 위치");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_board[row, col] = Enums.PlayerType.PlayerA;
|
|
||||||
Debug.Log($"Player's row: {row} col: {col}");
|
|
||||||
|
|
||||||
// var isEnded = MiniMaxAIController.CheckGameWin(Enums.PlayerType.PlayerA, _board, row, col);
|
|
||||||
// Debug.Log("PlayerA is Win: " + isEnded);
|
|
||||||
|
|
||||||
// 인공지능 호출
|
|
||||||
var result = MiniMaxAIController.GetBestMove(_board);
|
|
||||||
|
|
||||||
if (result.HasValue)
|
|
||||||
{
|
|
||||||
Debug.Log($"AI's row: {result.Value.row} col: {result.Value.col}");
|
|
||||||
_board[result.Value.row, result.Value.col] = Enums.PlayerType.PlayerB;
|
|
||||||
|
|
||||||
// isEnded = MiniMaxAIController.CheckGameWin(Enums.PlayerType.PlayerB, _board, result.Value.row, result.Value.col);
|
|
||||||
// Debug.Log("PlayerB is Win: " + isEnded);
|
|
||||||
}
|
|
||||||
|
|
||||||
ResultBoard();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ResultBoard()
|
|
||||||
{
|
|
||||||
boardText.text = "";
|
|
||||||
|
|
||||||
// player 타입에 따라 입력받는 건 무조건 A로 해서 A, AI는 B로 나타내고 None은 _
|
|
||||||
for (int i = 0; i < 15; i++)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < 15; j++)
|
|
||||||
{
|
|
||||||
if (_board[i, j] == Enums.PlayerType.PlayerA)
|
|
||||||
{
|
|
||||||
boardText.text += 'A';
|
|
||||||
}
|
|
||||||
else if (_board[i, j] == Enums.PlayerType.PlayerB)
|
|
||||||
{
|
|
||||||
boardText.text += 'B';
|
|
||||||
}
|
|
||||||
else if (_board[i, j] == Enums.PlayerType.None)
|
|
||||||
{
|
|
||||||
boardText.text += '_';
|
|
||||||
}
|
|
||||||
|
|
||||||
boardText.text += ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
boardText.text += '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: facc79abb6042e846bb0a2b099b58e9c
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -282,7 +282,7 @@ public class GameLogic : MonoBehaviour
|
|||||||
ReplayManager.Instance.RecordStonePlaced(Enums.StoneType.Black, row, col); //기보 데이터 저장
|
ReplayManager.Instance.RecordStonePlaced(Enums.StoneType.Black, row, col); //기보 데이터 저장
|
||||||
break;
|
break;
|
||||||
case Enums.PlayerType.PlayerB:
|
case Enums.PlayerType.PlayerB:
|
||||||
|
/*
|
||||||
// AI 테스트 시작
|
// AI 테스트 시작
|
||||||
OmokAI.Instance.StartBestMoveSearch(_board, (bestMove) =>
|
OmokAI.Instance.StartBestMoveSearch(_board, (bestMove) =>
|
||||||
{
|
{
|
||||||
@ -298,15 +298,15 @@ public class GameLogic : MonoBehaviour
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// AI 테스트 끝
|
// AI 테스트 끝
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
stoneController.SetStoneType(Enums.StoneType.White, row, col);
|
stoneController.SetStoneType(Enums.StoneType.White, row, col);
|
||||||
stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
|
stoneController.SetStoneState(Enums.StoneState.LastPositioned, row, col);
|
||||||
_board[row, col] = Enums.PlayerType.PlayerB;
|
_board[row, col] = Enums.PlayerType.PlayerB;
|
||||||
LastNSelectedSetting(row, col);
|
LastNSelectedSetting(row, col);
|
||||||
|
|
||||||
ReplayManager.Instance.RecordStonePlaced(Enums.StoneType.White, row, col);
|
ReplayManager.Instance.RecordStonePlaced(Enums.StoneType.White, row, col);
|
||||||
*/
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user