From 526e869eab9aec57341fa043900ea850c364b10d Mon Sep 17 00:00:00 2001 From: se_ga Date: Tue, 3 Mar 2026 17:03:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Fonts/NEW/NexaRegular COOL.asset | 2 +- Assets/Scenes/GameScene3D.unity | 64 ++++ .../1Easy/1tosterM1_easy.asset | 4 +- .../1Easy/1tosterM2_medium.asset | 4 +- .../1Easy/1tosterM3_hard.asset | 4 +- .../2Medium/1tosterM1_easy.asset | 4 +- .../2Medium/1tosterM2_medium.asset | 4 +- .../2Medium/1tosterM3_hard.asset | 4 +- .../3Hard/1tosterM1_easy.asset | 4 +- .../3Hard/1tosterM2_medium.asset | 4 +- .../3Hard/1tosterM3_hard.asset | 4 +- Assets/Scripts/CheckResult.cs | 29 +- Assets/Scripts/FieldModel.cs | 285 +++++++++--------- Assets/Scripts/GameFSM/BotThinkingState.cs | 11 +- Assets/Scripts/GameFSM/CheckState.cs | 120 ++++---- Assets/Scripts/GameFSM/ChipFallingState.cs | 4 +- Assets/Scripts/GameFSM/ShowWinnerState.cs | 43 +-- 17 files changed, 321 insertions(+), 273 deletions(-) diff --git a/Assets/Fonts/NEW/NexaRegular COOL.asset b/Assets/Fonts/NEW/NexaRegular COOL.asset index e184f94..eb3cfcd 100644 --- a/Assets/Fonts/NEW/NexaRegular COOL.asset +++ b/Assets/Fonts/NEW/NexaRegular COOL.asset @@ -11349,7 +11349,7 @@ Material: - _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767} - _EnvMatrixRotation: {r: 0, g: 0, b: 0, a: 0} - _FaceColor: {r: 1, g: 1, b: 1, a: 1} - - _GlowColor: {r: 0.6607363, g: 1, b: 0, a: 1} + - _GlowColor: {r: 0, g: 1, b: 0.28621435, a: 1} - _MaskCoord: {r: 0, g: 0, b: 32767, a: 32767} - _OutlineColor: {r: 0.554717, g: 0.554717, b: 0.554717, a: 1} - _ReflectFaceColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/Scenes/GameScene3D.unity b/Assets/Scenes/GameScene3D.unity index b79c1df..3982d92 100644 --- a/Assets/Scenes/GameScene3D.unity +++ b/Assets/Scenes/GameScene3D.unity @@ -24603,6 +24603,37 @@ MonoBehaviour: m_FlexibleWidth: -1 m_FlexibleHeight: -1 m_LayoutPriority: 1 +--- !u!1 &857054344 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 857054345} + m_Layer: 0 + m_Name: UnityMainThreadDispatcher + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &857054345 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 857054344} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, 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!1 &858131135 GameObject: m_ObjectHideFlags: 0 @@ -33367,6 +33398,37 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1072006378} m_CullTransparentMesh: 1 +--- !u!1 &1077429573 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1077429574} + m_Layer: 0 + m_Name: UnityMainThreadDispatcher + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1077429574 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1077429573} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, 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!1 &1077860246 GameObject: m_ObjectHideFlags: 0 @@ -72731,3 +72793,5 @@ SceneRoots: - {fileID: 2115833904} - {fileID: 1165555974} - {fileID: 592995719} + - {fileID: 857054345} + - {fileID: 1077429574} diff --git a/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM1_easy.asset b/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM1_easy.asset index 518d59e..1140b79 100644 --- a/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM1_easy.asset +++ b/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM1_easy.asset @@ -26,6 +26,4 @@ MonoBehaviour: TopK: 5 AvoidLossBanProb: 0 IMMEDIATE_LOSS_PENALTY: 20 - additionalPresets: - - preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2} - turns: 5 + additionalPresets: [] diff --git a/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM2_medium.asset b/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM2_medium.asset index 07e8fa1..54ea113 100644 --- a/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM2_medium.asset +++ b/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM2_medium.asset @@ -26,6 +26,4 @@ MonoBehaviour: TopK: 5 AvoidLossBanProb: 0 IMMEDIATE_LOSS_PENALTY: 20 - additionalPresets: - - preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2} - turns: 7 + additionalPresets: [] diff --git a/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM3_hard.asset b/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM3_hard.asset index 8fa78c6..bb01044 100644 --- a/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM3_hard.asset +++ b/Assets/Scripts/CharacterS/DifficultyPresets/1Easy/1tosterM3_hard.asset @@ -26,6 +26,4 @@ MonoBehaviour: TopK: 5 AvoidLossBanProb: 0 IMMEDIATE_LOSS_PENALTY: 20 - additionalPresets: - - preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2} - turns: 7 + additionalPresets: [] diff --git a/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM1_easy.asset b/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM1_easy.asset index de0f128..49a9813 100644 --- a/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM1_easy.asset +++ b/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM1_easy.asset @@ -26,6 +26,4 @@ MonoBehaviour: TopK: 5 AvoidLossBanProb: 0 IMMEDIATE_LOSS_PENALTY: 20 - additionalPresets: - - preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2} - turns: 7 + additionalPresets: [] diff --git a/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM2_medium.asset b/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM2_medium.asset index 08ac7ac..9357dc9 100644 --- a/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM2_medium.asset +++ b/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM2_medium.asset @@ -26,6 +26,4 @@ MonoBehaviour: TopK: 5 AvoidLossBanProb: 0 IMMEDIATE_LOSS_PENALTY: 20 - additionalPresets: - - preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2} - turns: 9 + additionalPresets: [] diff --git a/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM3_hard.asset b/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM3_hard.asset index 41d7841..a6ce4c7 100644 --- a/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM3_hard.asset +++ b/Assets/Scripts/CharacterS/DifficultyPresets/2Medium/1tosterM3_hard.asset @@ -26,6 +26,4 @@ MonoBehaviour: TopK: 5 AvoidLossBanProb: 0 IMMEDIATE_LOSS_PENALTY: 20 - additionalPresets: - - preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2} - turns: 9 + additionalPresets: [] diff --git a/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM1_easy.asset b/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM1_easy.asset index be137b6..718d174 100644 --- a/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM1_easy.asset +++ b/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM1_easy.asset @@ -26,6 +26,4 @@ MonoBehaviour: TopK: 5 AvoidLossBanProb: 0 IMMEDIATE_LOSS_PENALTY: 20 - additionalPresets: - - preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2} - turns: 9 + additionalPresets: [] diff --git a/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM2_medium.asset b/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM2_medium.asset index 116a572..a34ae50 100644 --- a/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM2_medium.asset +++ b/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM2_medium.asset @@ -26,6 +26,4 @@ MonoBehaviour: TopK: 5 AvoidLossBanProb: 0 IMMEDIATE_LOSS_PENALTY: 20 - additionalPresets: - - preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2} - turns: 11 + additionalPresets: [] diff --git a/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM3_hard.asset b/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM3_hard.asset index 6cc844c..e4593d9 100644 --- a/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM3_hard.asset +++ b/Assets/Scripts/CharacterS/DifficultyPresets/3Hard/1tosterM3_hard.asset @@ -26,6 +26,4 @@ MonoBehaviour: TopK: 5 AvoidLossBanProb: 0 IMMEDIATE_LOSS_PENALTY: 20 - additionalPresets: - - preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2} - turns: 11 + additionalPresets: [] diff --git a/Assets/Scripts/CheckResult.cs b/Assets/Scripts/CheckResult.cs index c38886b..47af517 100644 --- a/Assets/Scripts/CheckResult.cs +++ b/Assets/Scripts/CheckResult.cs @@ -1,24 +1,13 @@ -using UnityEngine; - +using System.Collections.Generic; public class CheckResult { - public bool end; - public bool draw; - public int[] indexesRow; - public int[] indexesColumn; - - public CheckResult(bool endgame, bool isDraw) + public bool End; + public bool Draw; + public HashSet<(int row, int col)> WinningIndexes; + public CheckResult(bool end, bool isDraw, HashSet<(int row, int col)> winningIndexes) { - end = endgame; - draw = isDraw; - } - public CheckResult(bool result, bool isDraw, int[] indexesRow, int[] indexesColumn) - { - end = result; - draw = isDraw; - this.indexesRow = indexesRow; - this.indexesColumn = indexesColumn; - } - - + End = end; + Draw = isDraw; + WinningIndexes = winningIndexes; + } } diff --git a/Assets/Scripts/FieldModel.cs b/Assets/Scripts/FieldModel.cs index 6443d69..494684b 100644 --- a/Assets/Scripts/FieldModel.cs +++ b/Assets/Scripts/FieldModel.cs @@ -1,5 +1,5 @@ using System; -using UnityEngine; +using System.Collections.Generic; public enum CellState { @@ -8,201 +8,210 @@ public enum CellState public class FieldModel { //äâóìåðíûé ìàññèâ äëÿ ïîëÿ - public CellState[,] fieldArr; - public int height, width; - - - // Êåøèðîâàííûå ìàññèâû äëÿ èçáåæàíèÿ àëëîêàöèé - private static readonly int[] tempIndexesRow = new int[4]; - private static readonly int[] tempIndexesColumn = new int[4]; + public CellState[,] FieldArray; + public int Height; + public int Width; + public int TargetLineLength = 4; public FieldModel(int width, int height) { //0 èíäåêñ äëÿ ñòðîê, 1 èíäåêñ äëÿ ñòîëáöîâ - this.width = width; - this.height = height; + Width = width; + Height = height; makeEmptyField(width, height); } public void makeEmptyField(int width, int height) { - fieldArr = new CellState[height, width]; - Array.Clear(fieldArr, 0, fieldArr.Length); + FieldArray = new CellState[height, width]; + Array.Clear(FieldArray, 0, FieldArray.Length); } - //Îñíîâíûå ïðîâåðêè ñ ðàçâåðíóòûì ðåçóëüòàòîì - public CheckResult check(int row, int col) + public CheckResult Check(CellState lastPlayer) { - CheckResult result; + HashSet<(int row, int col)> WinningIndexes = new(); - result = checkRow(row); - if (result.end) return result; + var rowsResult = checkAllRows(lastPlayer); + var colsResult = checkAllColumns(lastPlayer); + var diagonalsResult = checkAllDiagonals(lastPlayer); - result = checkColumn(col); - if (result.end) return result; + bool hasWin = rowsResult.hasWin || + colsResult.hasWin || + diagonalsResult.hasWin; - result = checkDiagonalDownUp(row, col); - if (result.end) return result; - - result = checkDiagonalUpDown(row, col); - if (result.end) return result; - - if (checkDraw()) + if (hasWin) { - return new CheckResult(true, true); + WinningIndexes.UnionWith(rowsResult.winningIndexes); + WinningIndexes.UnionWith(colsResult.winningIndexes); + WinningIndexes.UnionWith(diagonalsResult.winningIndexes); + + return new CheckResult(end: true, + isDraw: false, + WinningIndexes); + } + else if (checkDraw()) + { + return new CheckResult(end: true, + isDraw: true, + WinningIndexes); + } + else + { + return new CheckResult(end: false, + isDraw: false, + WinningIndexes); } - return result; + + } - public CheckResult checkRow(int row) + private (bool hasWin, HashSet<(int row, int col)> winningIndexes) checkAllRows(CellState targetCellState) { - CellState currentPlayer = GameManager.instance.currentPlayer; + var winningCells = new HashSet<(int row, int col)>(); - - int lineLength = 0; - for (int col = 0; col < width; col++) + for (int row = 0; row < Height; row++) { - CellState cell = fieldArr[row, col]; - if (cell != currentPlayer) + int start = -1; + + for (int col = 0; col <= Width; col++) // òåïåðü ïðîõîäèì äî Width âêëþ÷èòåëüíî { - lineLength = 0; - continue; - } - lineLength++; - - if (lineLength == 4)//íàøëè ðÿä èç 4 ôèøåê - { - //ìàññèâû ÷òîáû çàïîìíèòü èç-çà êàêîé êîìáèíàöèè ïðîèçîøëà ïîáåäà - //int[] indexesRow = new int[4]; - //int[] indexesColumn = new int[4]; - for (int i = 0; i < 4; i++) + // Ïðîâåðÿåì, íå âûøëè ëè çà ãðàíèöû ìàññèâà + bool isMatch = col < Width && FieldArray[row, col] == targetCellState; + + if (isMatch && start == -1) + start = col; + + if ((!isMatch || col == Width) && start != -1) { - //indexesColumn[i] = col - i; - //indexesRow[i] = row; - tempIndexesColumn[i] = col - i; - tempIndexesRow[i] = row; + int length = col - start; + if (length >= TargetLineLength) + { + for (int c = start; c < col; c++) + winningCells.Add((row, c)); + } + start = -1; } - return new CheckResult(true, false, tempIndexesRow, tempIndexesColumn); } } - return new CheckResult(false, false);//íå íàøëè êîìáèíàöèþ + + return (winningCells.Count > 0, winningCells); } - public CheckResult checkColumn(int column) + private (bool hasWin, HashSet<(int row, int col)> winningIndexes) checkAllColumns(CellState targetCellState) { - CellState currentPlayer = GameManager.instance.currentPlayer; - int lineLength = 0; - for (int row = height - 1; row >= 0; row--) - { - CellState cell = fieldArr[row, column]; - if (cell != currentPlayer) - { - lineLength = 0; - continue; - } - lineLength++; + var winningCells = new HashSet<(int row, int col)>(); - if (lineLength == 4)//íàøëè ðÿä èç 4 ôèøåê + for (int col = 0; col < Width; col++) + { + int start = -1; + + for (int row = 0; row <= Height; row++) { - for (int i = 0; i < 4; i++) + bool isMatch = row < Height && FieldArray[row, col] == targetCellState; + + if (isMatch && start == -1) + start = row; + + if ((!isMatch || row == Height) && start != -1) { - tempIndexesColumn[i] = column; - tempIndexesRow[i] = row + i; + int length = row - start; + if (length >= TargetLineLength) + { + for (int r = start; r < row; r++) + winningCells.Add((r, col)); + } + start = -1; } - return new CheckResult(true,false,tempIndexesRow, tempIndexesColumn); } } - return new CheckResult(false, false);//íå íàøëè êîìáèíàöèþ + return (winningCells.Count > 0, winningCells); } - public CheckResult checkDiagonalDownUp(int row, int col) + + private (bool hasWin, HashSet<(int row, int col)> winningIndexes) checkAllDiagonals(CellState targetCellState) { - CellState currentPlayer = GameManager.instance.currentPlayer; - int sum = row + col; + var winningCells = new HashSet<(int row, int col)>(); - // Äèàãîíàëü ñëèøêîì êîðîòêàÿ, åñëè ñóììà ìåíüøå ìèíèìàëüíîé (3) èëè áîëüøå ìàêñèìàëüíîé (height+width-4) - if (sum < 3 || sum > height + width - 4) - return new CheckResult(false, false); - - // Âû÷èñëÿåì íà÷àëüíóþ òî÷êó äèàãîíàëè - int startRow = Mathf.Clamp(sum, 0, height - 1); - int startCol = Mathf.Clamp(sum - (height - 1), 0, width - 1); - - int lineLength = 0; - - for (row = startRow, col = startCol; row >= 0 && col < width; row--, col++) + // Ïðîâåðêà ãëàâíûõ äèàãîíàëåé + for (int row = 0; row < Height; row++) { - CellState cell = fieldArr[row, col]; - if (cell != currentPlayer) - { - lineLength = 0; - continue; - } - lineLength++; - if (lineLength == 4) - { - for (int i = 0; i < 4; i++) - { - tempIndexesRow[i] = row + i; - tempIndexesColumn[i] = col - i; - } - return new CheckResult(true, false, tempIndexesRow, tempIndexesColumn); - } + CheckDiagonalStartingAt(row, 0, 1, 1, targetCellState, winningCells); } - return new CheckResult(false, false); + for (int col = 1; col < Width; col++) + { + CheckDiagonalStartingAt(0, col, 1, 1, targetCellState, winningCells); + } + + // Ïðîâåðêà ïîáî÷íûõ äèàãîíàëåé + for (int row = 0; row < Height; row++) + { + CheckDiagonalStartingAt(row, Width - 1, 1, -1, targetCellState, winningCells); + } + for (int col = Width - 2; col >= 0; col--) + { + CheckDiagonalStartingAt(0, col, 1, -1, targetCellState, winningCells); + } + + return (winningCells.Count > 0, winningCells); } - public CheckResult checkDiagonalUpDown(int row, int col) + + private void CheckDiagonalStartingAt(int startRow, int startCol, int rowStep, int colStep, + CellState targetCellState, HashSet<(int, int)> winningCells) { - CellState currentPlayer = GameManager.instance.currentPlayer; - int sub = row - col; + int rows = Height; + int cols = Width; + int currentRow = startRow; + int currentCol = startCol; + int sequenceLength = 0; + int sequenceStartRow = startRow; + int sequenceStartCol = startCol; - // Íà÷àëüíàÿ òî÷êà äèàãîíàëè, ïðîõîäÿùåé ÷åðåç (row, col) - int startRow = sub >= 0 ? sub : 0; - int startCol = sub >= 0 ? 0 : -sub; - - int lineLength = 0; - - for (row = startRow, col = startCol; row < height && col < width; row++, col++) + while (currentRow >= 0 && currentRow < rows && + currentCol >= 0 && currentCol < cols) { - CellState cell = fieldArr[row, col]; - if (cell != currentPlayer) - { - lineLength = 0; - continue; - } - lineLength++; - if (lineLength == 4) - { - for (int i = 0; i < 4; i++) - { - tempIndexesColumn[i] = col - i; - tempIndexesRow[i] = row - i; - } - return new CheckResult(true, false, tempIndexesRow, tempIndexesColumn); - } - } - return new CheckResult(false, false); - } + bool isMatch = FieldArray[currentRow, currentCol] == targetCellState; + if (isMatch) + { + sequenceLength++; + + if (sequenceLength >= TargetLineLength) + { + // Äîáàâëÿåì ÂÑÅ ÿ÷åéêè èç òåêóùåé ïîñëåäîâàòåëüíîñòè + for (int i = 0; i < sequenceLength; i++) + { + int r = sequenceStartRow + i * rowStep; + int c = sequenceStartCol + i * colStep; + winningCells.Add((r, c)); + } + } + } + else + { + sequenceLength = 0; + sequenceStartRow = currentRow + rowStep; + sequenceStartCol = currentCol + colStep; + } + + currentRow += rowStep; + currentCol += colStep; + } + } public int getHeight(int colIndex) { - //ïåðåáèðàåì ðÿäû äëÿ âûáðàííîé êîëîíêè - //èùåì ñàìûé íèæíèé ñëîò â êîëîíêå, êóäà ìîæåì âñòàâèòü ôèøêó - for (int row = height-1; row >= 0; row--) + for (int row = Height - 1; row >= 0; row--) { - if (fieldArr[row, colIndex] == CellState.Empty) + if (FieldArray[row, colIndex] == CellState.Empty) { return row; } } return -1;//åñëè íå íàøëè, òî áîëüøå äîáàâèòü íåëüçÿ } - - //ïðîâåðêà íè÷üåé + public bool checkDraw() { - for (int col = 0; col < width; col++) + for (int col = 0; col < Width; col++) { - //åñëè åñòü õîòü îäíà íåïóñòàÿ êîëîíêà òî èãðà ïðîäîëæàåòñÿ if (getHeight(col) != -1) return false; } return true; diff --git a/Assets/Scripts/GameFSM/BotThinkingState.cs b/Assets/Scripts/GameFSM/BotThinkingState.cs index d0e9468..597e320 100644 --- a/Assets/Scripts/GameFSM/BotThinkingState.cs +++ b/Assets/Scripts/GameFSM/BotThinkingState.cs @@ -30,7 +30,7 @@ public class BotThinkingState : IState //УÑ�тановка преÑ�ета Ñ�ложноÑ�ти DifficultyPreset currentPreset = CharacterController.CurrentCharacter.CurrentDifficultyPreset; - //Debug.Log(currentPreset.Description); + Debug.Log(currentPreset.Description); if (GameManager.instance.dummyBots) currentPreset = GameManager.instance.dummyPreset; @@ -120,17 +120,18 @@ public class BotThinkingState : IState bool NeedSuperPreset = OnBossByScore && (IsHardCommonDifficulty || IsUpperCashDifficulty); + //NeedSuperPreset = true; + + Debug.Log($"ИÑ�пользовать Ñ�уперÑ�ложноÑ�ть: {NeedSuperPreset}\nСейчаÑ� боÑ�Ñ�: {OnBossByScore}\nСложнаÑ� Ñ�ложноÑ�ть: {IsHardCommonDifficulty}\nВключен режим заработка: {IsUpperCashDifficulty}\n"); - - if (NeedSuperPreset) { - calculatedColumn = SolverV2.FindBestMove(GameManager.fieldModel.fieldArr, GameManager.instance.currentPlayer); + calculatedColumn = SolverV2.FindBestMove(GameManager.fieldModel.FieldArray, GameManager.instance.currentPlayer); } else { - calculatedColumn = Solver.FindBestMove(GameManager.fieldModel.fieldArr, GameManager.instance.currentPlayer); + calculatedColumn = Solver.FindBestMove(GameManager.fieldModel.FieldArray, GameManager.instance.currentPlayer); } } diff --git a/Assets/Scripts/GameFSM/CheckState.cs b/Assets/Scripts/GameFSM/CheckState.cs index 3c2d05d..24941aa 100644 --- a/Assets/Scripts/GameFSM/CheckState.cs +++ b/Assets/Scripts/GameFSM/CheckState.cs @@ -1,21 +1,22 @@ -using System.Collections.Generic; -using UnityEngine; +using UnityEngine; public class CheckState : IState { GameManager gm; - int row, col; bool timerWin; - public CheckState(int row, int col) - { - this.row = row; - this.col = col; - timerWin = false; - } + + CheckResult result; + + + public CheckState() : this(false) + { } public CheckState(bool timerWin) { - if (timerWin) this.timerWin = true; - else this.timerWin = false; + this.timerWin = timerWin; + + result = timerWin ? new CheckResult(true, false, null) : GameManager.fieldModel.Check(GameManager.instance.currentPlayer); + gm = GameManager.instance; + gm.lastResult = result; } public void enter() @@ -35,18 +36,17 @@ public class CheckState : IState { bool swipeToNextRightNow = false; - CheckResult result = GameManager.fieldModel.check(row, col); - gm.lastResult = result; + IState nextState; //pvp решение победа в раунде или в игре - bool endround = false; + bool endround = result.End && !result.Draw; bool endgame = false; // подÑ�чет очков - if (result.end)//Раунд окончен. Считаем очки и Ñ�тавим Ñ�тейт показ победителÑ� + if (result.End)//Раунд окончен. Считаем очки и Ñ�тавим Ñ�тейт показ победителÑ� { - if (gm.gameMode == GameMode.pvp && !result.draw) + if (gm.gameMode == GameMode.pvp && !result.Draw) { //победил p1 if (gm.currentPlayer == CellState.Player1) @@ -59,23 +59,22 @@ public class CheckState : IState gm.player2score += 1; gm.Player2Scale.SetMedalsCount(gm.player2score); } - - endround = true; - if (gm.player1score == 5 || gm.player2score == 5) + + if (gm.player1score == 5 || gm.player2score == 5) endgame = true; if (endgame) AvatarEventBus.Instance.OnEndGame?.Invoke(gm.currentPlayer); - else if(endround) + else if (endround) AvatarEventBus.Instance.OnEndRound?.Invoke(gm.currentPlayer); } - else if (gm.gameMode == GameMode.pve && !result.draw) //конец раунда Ñ� ботом + else if (gm.gameMode == GameMode.pve && !result.Draw) //конец раунда Ñ� ботом { //Ð�Е Ð�ИЧЬЯ VictoryScale botScale = gm.botScale; - + if (gm.currentPlayer == CellState.Player1)//[ПОБЕДÐ� ИГРОКÐ�] { if (CharacterController.CurrentCharacter.HasPrize) @@ -91,9 +90,8 @@ public class CheckState : IState LightUtility.Win(); CharacterController.CurrentCharacter.GetComponent().SetTrigger("Lose"); - + swipeToNextRightNow = true; - //swipeToNextRightNow = false; } else//Бот победил { @@ -107,7 +105,7 @@ public class CheckState : IState } botScale.SetMedalsCount(gm.vsBotScore); } - else if (gm.gameMode == GameMode.pve && result.draw) + else if (gm.gameMode == GameMode.pve && result.Draw) { CharacterEventBus.Instance.OnDraw?.Invoke(); } @@ -123,13 +121,10 @@ public class CheckState : IState if (gm.gameMode == GameMode.pve && gm.vsBotScore == gm.botsAmount) gm.upgradeFeeshkaDifficulty(); //конец игры - призовое Ñ�оÑ�тоÑ�ние - if (gm.player1score == 5 || gm.player2score == 5 || gm.vsBotScore == gm.botsAmount) + if (IsEndGame()) { nextState = new PrizeState(); - - if (gm.botScale.isActiveAndEnabled) gm.botScale.ClearScale(); - if (gm.Player1Scale.isActiveAndEnabled) gm.Player1Scale.ClearScale(); - if (gm.Player2Scale.isActiveAndEnabled) gm.Player2Scale.ClearScale(); + ClearAllScales(); } else if (swipeToNextRightNow) { @@ -142,62 +137,63 @@ public class CheckState : IState gm.stateMachine.ChangeState(nextState); } + private bool IsEndGame() => + gm.player1score == 5 || gm.player2score == 5 || gm.vsBotScore == gm.botsAmount; + void WinByTimerHandling() { //запуÑ�тить проверку по полю - CheckResult result = new CheckResult(true, false, null, null); - gm.lastResult = result; + IState nextState; - if (gm.gameMode == GameMode.pvp) + if (gm.gameMode == GameMode.pvp && !result.Draw) { - if (!result.draw) + //p2 не уÑ�пел + if (gm.currentPlayer == CellState.Player2) { - //p2 не уÑ�пел - if (gm.currentPlayer == CellState.Player2) - { - gm.player1score += 1; - gm.Player1Scale.SetMedalsCount(gm.player1score); - } - else//p1 не уÑ�пел - { - gm.player2score += 1; - gm.Player2Scale.SetMedalsCount(gm.player2score); - } + gm.player1score += 1; + gm.Player1Scale.SetMedalsCount(gm.player1score); + } + else//p1 не уÑ�пел + { + gm.player2score += 1; + gm.Player2Scale.SetMedalsCount(gm.player2score); } } - else if (gm.gameMode == GameMode.pve)//времÑ� вышло при игре Ñ� ботом - бот победил + else if (gm.gameMode == GameMode.pve && !result.Draw)//времÑ� вышло при игре Ñ� ботом - бот победил { - if (!result.draw) - { - LightUtility.Lose(); - CharacterController.CurrentCharacter.GetComponent().SetTrigger("Win"); + LightUtility.Lose(); + CharacterController.CurrentCharacter.GetComponent().SetTrigger("Win"); - //Ð�Е Ð�ИЧЬЯ - VictoryScale vsBotScale = gm.botScale; - DifficultyManager.instance.DecreaseDifficulty(); - CharacterEventBus.Instance.OnBotWin?.Invoke(); - if (gm.vsBotScore != 0) gm.vsBotScore -= 1; + //Ð�Е Ð�ИЧЬЯ + VictoryScale vsBotScale = gm.botScale; + DifficultyManager.instance.DecreaseDifficulty(); + CharacterEventBus.Instance.OnBotWin?.Invoke(); + if (gm.vsBotScore != 0) gm.vsBotScore -= 1; - vsBotScale.SetMedalsCount(gm.vsBotScore); - } + vsBotScale.SetMedalsCount(gm.vsBotScore); } nextState = new ShowWinnerState(result); //конец игры - призовое Ñ�оÑ�тоÑ�ние - if (gm.player1score == 5 || gm.player2score == 5 || gm.vsBotScore == gm.botsAmount) + if (IsEndGame()) { nextState = new PrizeState(); - - if (gm.botScale.isActiveAndEnabled) gm.botScale.ClearScale(); - if (gm.Player1Scale.isActiveAndEnabled) gm.Player1Scale.ClearScale(); - if (gm.Player2Scale.isActiveAndEnabled) gm.Player2Scale.ClearScale(); + ClearAllScales(); } gm.stateMachine.ChangeState(nextState); } + + private void ClearAllScales() + { + if (gm.botScale.isActiveAndEnabled) gm.botScale.ClearScale(); + if (gm.Player1Scale.isActiveAndEnabled) gm.Player1Scale.ClearScale(); + if (gm.Player2Scale.isActiveAndEnabled) gm.Player2Scale.ClearScale(); + } + public void exit() { diff --git a/Assets/Scripts/GameFSM/ChipFallingState.cs b/Assets/Scripts/GameFSM/ChipFallingState.cs index d811bce..be8e9ff 100644 --- a/Assets/Scripts/GameFSM/ChipFallingState.cs +++ b/Assets/Scripts/GameFSM/ChipFallingState.cs @@ -125,9 +125,9 @@ public class ChipFallingState : IState private void CompleteChipLanding() { chipTransform.position = targetPosition; - GameManager.fieldModel.fieldArr[rowIndex, colIndex] = GameManager.instance.currentPlayer; + GameManager.fieldModel.FieldArray[rowIndex, colIndex] = GameManager.instance.currentPlayer; GameManager.instance.setChipTransformToArray(rowIndex, colIndex, chipTransform); - GameManager.instance.stateMachine.ChangeState(new CheckState(rowIndex, colIndex)); + GameManager.instance.stateMachine.ChangeState(new CheckState()); } #endregion diff --git a/Assets/Scripts/GameFSM/ShowWinnerState.cs b/Assets/Scripts/GameFSM/ShowWinnerState.cs index 2e21245..ef993a1 100644 --- a/Assets/Scripts/GameFSM/ShowWinnerState.cs +++ b/Assets/Scripts/GameFSM/ShowWinnerState.cs @@ -73,13 +73,13 @@ public class ShowWinnerState : IState right= GameManager.MenuButton; InitPanel(); - if (result.draw) + if (result.Draw) { GameManager.DrawVisual.Show(); } if (GameManager.gameMode == GameMode.pvp) { - if (!result.draw) + if (!result.Draw) { LightUtility.Win(); winningChips = new List(); @@ -107,7 +107,7 @@ public class ShowWinnerState : IState } else if (GameManager.gameMode == GameMode.pve) { - if (!result.draw) + if (!result.Draw) { winningChips = new List(); CollectChipsList(result); @@ -140,7 +140,7 @@ public class ShowWinnerState : IState { ToMenuLabel.gameObject.SetActive(false); - if (result.draw) + if (result.Draw) { GameManager.DrawVisual.Hide(); return; @@ -177,7 +177,7 @@ public class ShowWinnerState : IState ExitByTime(); break; } - if (!result.draw) + if (!result.Draw) BlinkChips(); } @@ -236,7 +236,7 @@ public class ShowWinnerState : IState if (panel.localPosition == targetUpPosition) { - if (GameManager.lastResult != null && !GameManager.lastResult.draw) + if (GameManager.lastResult != null && !GameManager.lastResult.Draw) { foreach (SpriteRenderer chip in winningChips) { @@ -386,21 +386,28 @@ public class ShowWinnerState : IState void CollectChipsList(CheckResult result) { - if (result.indexesRow == null) return; //кто то победил по таймеру + if (result.WinningIndexes == null) return; //кто то победил по таймеру - for (int i = 0; i < 4; i++) + foreach (var index in result.WinningIndexes) { - int row = result.indexesRow[i]; - int col = result.indexesColumn[i]; - - GameManager.chipTransforms[row, col].rotation = Quaternion.identity; - - winningChips.Add(GameManager.chipTransforms[row, col].GetChild(0) - .GetComponent()); - - winningChips[i].AddComponent().speed = 8; - + GameManager.chipTransforms[index.row, index.col].rotation = Quaternion.identity; + var renderer = GameManager.chipTransforms[index.row, index.col].GetChild(0).GetComponent(); + winningChips.Add(renderer); + renderer.gameObject.AddComponent().speed = 8; } + //for (int i = 0; i < 4; i++) + //{ + // int row = result.indexesRow[i]; + // int col = result.indexesColumn[i]; + + // GameManager.chipTransforms[row, col].rotation = Quaternion.identity; + + // winningChips.Add(GameManager.chipTransforms[row, col].GetChild(0) + // .GetComponent()); + + // winningChips[i].AddComponent().speed = 8; + + //} } void BlinkChips() {