private void Generate() { for (int i = 0; i < poleRazmer; i++) { for (int j = 0; j < poleRazmer; j++) { cells[i, j] = (GameObject)Instantiate(cell, new Vector2(-3.5f + j * 1.25f, 4 - i * 1.25f), Quaternion.identity); CellEndlessGenerate cellPozition = cells[i, j].GetComponent <CellEndlessGenerate>(); cellPozition.x = j; cellPozition.y = i; } } }
IEnumerator addLine(int y)// Смещение и довабление новой строки { yield return(new WaitForEndOfFrame()); PlayerPoints -= 11; CompPoints -= 11; pointsTextPlayer.text = string.Format("{0}", PlayerPoints); pointsTextComp.text = string.Format("{0}", CompPoints); _addLine = true; for (int i = y - 1; i >= 0; i--)//Смещение { for (int j = 0; j < poleRazmer; j++) { if (cells[i, j] != null) { cells[i + 1, j] = cells[i, j]; cells[i + 1, j].gameObject.transform.position = new Vector2(cells[i + 1, j].gameObject.transform.position.x, cells[i + 1, j].gameObject.transform.position.y - 1.25f); CellEndlessGenerate _cells = cells[i + 1, j].GetComponent <CellEndlessGenerate>(); _cells.checkPosition(-1.25f); _cells.x = j; _cells.y = i + 1; cells[i, j] = null; } } } for (int j = 0; j < poleRazmer; j++) { cells[0, j] = (GameObject)Instantiate(cell, new Vector2(-3.5f + j * 1.25f, 4 - 0 * 1.25f), Quaternion.identity); CellEndlessGenerate cellPozition = cells[0, j].GetComponent <CellEndlessGenerate>(); cellPozition.x = j; cellPozition.y = 0; if (_turn == 1 && j == column) { PolygonCollider2D cellColl = cells[0, j].AddComponent <PolygonCollider2D>(); SpriteRenderer _render = cells[0, j].GetComponent <SpriteRenderer>(); _render.color = Color.blue; } } _addLine = false; }
IEnumerator CompStep(int x) { yield return(new WaitForSeconds(1f)); //GameObject compChoice = cells[AIchoice(_turn, x, 1), x]; memScore2 = CompPoints; memScore1 = PlayerPoints; GameObject compChoice = cells[AiChoice(_turn, x, 0), x]; for (int i = 0; i < 10; i++) { SpriteRenderer _render = compChoice.GetComponent <SpriteRenderer>(); Color color = new Color(1, 0.92f, 0.016f, 1); color.a -= i / 10; _render.color = color; yield return(new WaitForSeconds(0.1f)); } CellEndlessGenerate stepComp = compChoice.GetComponent <CellEndlessGenerate>(); stepComp.OnMouseDown(); }
public int AiChoice(int _turn, int _line, int dept) { dept++; int bestScore1 = -9999; int bestScore2 = -9999; int bestChoice = -1; int currScore1 = memScore1; int currScore2 = memScore2; int choice; int temp; for (int i = 0; i < poleRazmer; i++) { if (_turn == 0)//игрок { if (cells[_line, i] != null) { CellEndlessGenerate checkNumber = cells[_line, i].GetComponent <CellEndlessGenerate>(); if (Mathf.Abs(checkNumber.Number) == 99) { continue; } temp = checkNumber.Number; checkNumber.Number = 98; memScore1 = currScore1; memScore2 = currScore2 + temp; if (dept < maxDepth) { choice = AiChoice(1, i, dept); if ((memScore1 - memScore2 < bestScore1 - bestScore2 && (choice != -1 || (choice == -1 && memScore1 + PlayerPoints < memScore2 + CompPoints)) || bestScore1 == -9999)) { bestScore1 = memScore1; bestScore2 = memScore2; bestChoice = i; if (choice == -1 || memScore1 < 0) { bestScore2 += poleRazmer * 5; } } } else { if ((memScore1 - memScore2 < bestScore1 - bestScore2)) { bestScore1 = memScore1; bestScore2 = memScore2; bestChoice = i; } } checkNumber.Number = Mathf.Abs(temp) - 1; } else { continue; } } else { if (cells[i, _line] != null) { CellEndlessGenerate checkNumber = cells[i, _line].GetComponent <CellEndlessGenerate>(); if (Mathf.Abs(checkNumber.Number) == 99) { continue; } temp = checkNumber.Number; checkNumber.Number = 98; memScore1 = currScore1 + temp; memScore2 = currScore2; if (dept < maxDepth) { choice = AiChoice(0, i, dept); if ((memScore1 - memScore2 > bestScore1 - bestScore2 && (choice != -1 || (choice == -1 && memScore1 + PlayerPoints > memScore2 + CompPoints)) || bestScore1 == -9999)) { bestScore1 = memScore1; bestScore2 = memScore2; bestChoice = i; if (choice == -1 || memScore2 < 0) { bestScore1 += poleRazmer * 5; } } } else { if ((memScore1 - memScore2 > bestScore1 - bestScore2)) { bestScore1 = memScore1; bestScore2 = memScore2; bestChoice = i; } } checkNumber.Number = Mathf.Abs(temp) - 1; } } } if (bestScore1 != -9999) { memScore1 = bestScore1; memScore2 = bestScore2; } return(bestChoice); }