using System.Collections.Generic; using UnityEngine; public class NormalBotAI : IBotAI { protected EasyBotAI fallbackAI = new EasyBotAI(); public virtual Vector2Int MakeMove(GamePole pole) { int[] wrecked = pole.SearchWreckedShip(); if (wrecked != null) { Vector2Int? shot = ShotCross(pole, wrecked[0], wrecked[1], false); if (shot.HasValue) return shot.Value; } return fallbackAI.MakeMove(pole); } private Vector2Int? ShotCross(GamePole pole, int x, int y, bool twoAttempts) { int[,] directions = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; List dirs = new List { 0, 1, 2, 3 }; // Перемешиваем направления случайным образом for (int i = 0; i < dirs.Count; i++) { int r = Random.Range(i, dirs.Count); (dirs[i], dirs[r]) = (dirs[r], dirs[i]); } foreach (int d in dirs) { int dx = x + directions[d, 0]; int dy = y + directions[d, 1]; if (dx >= 0 && dx < pole.LengPole && dy >= 0 && dy < pole.LengPole) { if (pole.PoleShot[dx, dy] == 0) { return new Vector2Int(dx, dy); } } } // Если не нашли подходящего варианта, вызываем запасной AI return fallbackAI.MakeMove(pole); } }