/*Запуск просчета игры*/ public void RunGame(int X, int Y) { /*Наш ход*/ Cell[X, Y].color = 1; GamerChips--; /*Проверка, создан ли квадрат*/ SquereFound(1, true); /*Запускаю ход AI*/ ScoreAndCoordinates ScAndCrd = RunAI(); if (ComputerChips <= 0) { MessageBox.Show("Вы выйграли XDD"); Clear(); return; } Cell[ScAndCrd.coordinates.X, ScAndCrd.coordinates.Y].color = 2; ComputerChips--; SquereFound(2, true); if (GamerChips <= 0) { MessageBox.Show("Вы проиграли :(("); Clear(); return; } }
/*Ход AI*/ public ScoreAndCoordinates RunAI() { /*Новые координаты*/ ScoreAndCoordinates scoreInThis = new ScoreAndCoordinates(); /*Очки, чем их больше, тем выйгрышнее ситуация для компьютера, и наоборот*/ Int32 sc; int gamer; /*В зависимости от глубины, считаем ход либо для игрока, либо для компьютера*/ Coordinates cr = new Coordinates(-1, -1); sc = Int32.MinValue; gamer = 2; for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { if (Cell[x, y].color == 0) { /*Если ячека пуста, делаем ход*/ Cell[x, y].color = gamer; /*Запуск эвристики*/ scoreInThis.score = HeuristicEvaluation(); if (scoreInThis.score > sc) { sc = scoreInThis.score; cr.X = x; cr.Y = y; } /*Восстанавливаем ходы*/ Cell[x, y].color = 0; } } } /*Позвращаем полученные очки и координаты*/ scoreInThis.score = sc; scoreInThis.coordinates.X = cr.X; scoreInThis.coordinates.Y = cr.Y; return(scoreInThis); }