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); cell_battle cellPozition = cells[i, j].GetComponent <cell_battle>(); cellPozition.x = j; cellPozition.y = i; } } }
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)); } cell_battle stepComp = compChoice.GetComponent <cell_battle>(); 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) { cell_battle checkNumber = cells[_line, i].GetComponent <cell_battle>(); if (Mathf.Abs(checkNumber.Number) == 99) { continue; } temp = checkNumber.Number; checkNumber.Number = 98; if (temp > 0) { memScore1 = currScore1; if (currScore2 + temp < maxLife) { memScore2 = currScore2 + temp; } else { memScore2 = maxLife; } } else { memScore1 = currScore1 + temp; memScore2 = currScore2; } 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) { 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) { cell_battle checkNumber = cells[i, _line].GetComponent <cell_battle>(); if (Mathf.Abs(checkNumber.Number) == 99) { continue; } temp = checkNumber.Number; checkNumber.Number = 98; if (temp > 0) { if (currScore1 + temp < maxLife) { memScore1 = currScore1 + temp; } else { memScore1 = maxLife; } memScore2 = currScore2; } else { memScore1 = currScore1; memScore2 = currScore2 + temp; } 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) { 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); }