Рефакторинг модели поля
This commit is contained in:
parent
fe913acf9b
commit
526e869eab
@ -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}
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -26,6 +26,4 @@ MonoBehaviour:
|
||||
TopK: 5
|
||||
AvoidLossBanProb: 0
|
||||
IMMEDIATE_LOSS_PENALTY: 20
|
||||
additionalPresets:
|
||||
- preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2}
|
||||
turns: 5
|
||||
additionalPresets: []
|
||||
|
||||
@ -26,6 +26,4 @@ MonoBehaviour:
|
||||
TopK: 5
|
||||
AvoidLossBanProb: 0
|
||||
IMMEDIATE_LOSS_PENALTY: 20
|
||||
additionalPresets:
|
||||
- preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2}
|
||||
turns: 7
|
||||
additionalPresets: []
|
||||
|
||||
@ -26,6 +26,4 @@ MonoBehaviour:
|
||||
TopK: 5
|
||||
AvoidLossBanProb: 0
|
||||
IMMEDIATE_LOSS_PENALTY: 20
|
||||
additionalPresets:
|
||||
- preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2}
|
||||
turns: 7
|
||||
additionalPresets: []
|
||||
|
||||
@ -26,6 +26,4 @@ MonoBehaviour:
|
||||
TopK: 5
|
||||
AvoidLossBanProb: 0
|
||||
IMMEDIATE_LOSS_PENALTY: 20
|
||||
additionalPresets:
|
||||
- preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2}
|
||||
turns: 7
|
||||
additionalPresets: []
|
||||
|
||||
@ -26,6 +26,4 @@ MonoBehaviour:
|
||||
TopK: 5
|
||||
AvoidLossBanProb: 0
|
||||
IMMEDIATE_LOSS_PENALTY: 20
|
||||
additionalPresets:
|
||||
- preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2}
|
||||
turns: 9
|
||||
additionalPresets: []
|
||||
|
||||
@ -26,6 +26,4 @@ MonoBehaviour:
|
||||
TopK: 5
|
||||
AvoidLossBanProb: 0
|
||||
IMMEDIATE_LOSS_PENALTY: 20
|
||||
additionalPresets:
|
||||
- preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2}
|
||||
turns: 9
|
||||
additionalPresets: []
|
||||
|
||||
@ -26,6 +26,4 @@ MonoBehaviour:
|
||||
TopK: 5
|
||||
AvoidLossBanProb: 0
|
||||
IMMEDIATE_LOSS_PENALTY: 20
|
||||
additionalPresets:
|
||||
- preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2}
|
||||
turns: 9
|
||||
additionalPresets: []
|
||||
|
||||
@ -26,6 +26,4 @@ MonoBehaviour:
|
||||
TopK: 5
|
||||
AvoidLossBanProb: 0
|
||||
IMMEDIATE_LOSS_PENALTY: 20
|
||||
additionalPresets:
|
||||
- preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2}
|
||||
turns: 11
|
||||
additionalPresets: []
|
||||
|
||||
@ -26,6 +26,4 @@ MonoBehaviour:
|
||||
TopK: 5
|
||||
AvoidLossBanProb: 0
|
||||
IMMEDIATE_LOSS_PENALTY: 20
|
||||
additionalPresets:
|
||||
- preset: {fileID: 11400000, guid: 16e124f4ebd9a8f4fb0ecfee05ada9d2, type: 2}
|
||||
turns: 11
|
||||
additionalPresets: []
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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<Animator>().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<Animator>().SetTrigger("Win");
|
||||
LightUtility.Lose();
|
||||
CharacterController.CurrentCharacter.GetComponent<Animator>().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()
|
||||
{
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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<SpriteRenderer>();
|
||||
@ -107,7 +107,7 @@ public class ShowWinnerState : IState
|
||||
}
|
||||
else if (GameManager.gameMode == GameMode.pve)
|
||||
{
|
||||
if (!result.draw)
|
||||
if (!result.Draw)
|
||||
{
|
||||
winningChips = new List<SpriteRenderer>();
|
||||
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<SpriteRenderer>());
|
||||
|
||||
winningChips[i].AddComponent<SinRotator>().speed = 8;
|
||||
|
||||
GameManager.chipTransforms[index.row, index.col].rotation = Quaternion.identity;
|
||||
var renderer = GameManager.chipTransforms[index.row, index.col].GetChild(0).GetComponent<SpriteRenderer>();
|
||||
winningChips.Add(renderer);
|
||||
renderer.gameObject.AddComponent<SinRotator>().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<SpriteRenderer>());
|
||||
|
||||
// winningChips[i].AddComponent<SinRotator>().speed = 8;
|
||||
|
||||
//}
|
||||
}
|
||||
void BlinkChips()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user