46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CrazyBotAI : IBotAI
|
|
{
|
|
private Queue<Vector2Int> targetShipCoords = new Queue<Vector2Int>();
|
|
|
|
public Vector2Int MakeMove(GamePole pole)
|
|
{
|
|
if (targetShipCoords.Count > 0)
|
|
{
|
|
// Äîáèâàåì ïî çàðàíåå íàéäåííûì êîîðäèíàòàì
|
|
return targetShipCoords.Dequeue();
|
|
}
|
|
|
|
var shots = pole.GetAvailableShots();
|
|
if (shots.Count == 0)
|
|
return new Vector2Int(-1, -1); // Íåò êóäà ñòðåëÿòü
|
|
|
|
var shot = shots[Random.Range(0, shots.Count)];
|
|
return new Vector2Int(shot.x, shot.y);
|
|
|
|
}
|
|
|
|
// Ìåòîä äëÿ îáíîâëåíèÿ î÷åðåäè äîáèâàíèÿ ïîñëå óñïåøíîãî âûñòðåëà, âûçûâàåìûé ñíàðóæè
|
|
public void OnHitShip(GamePole pole, int x, int y)
|
|
{
|
|
var cell = pole.Pole[x, y].GetComponent<Cell>();
|
|
if (cell != null && cell.deck != null)
|
|
{
|
|
var ship = cell.deck.GetComponentInParent<Ship>();
|
|
if (ship != null)
|
|
{
|
|
foreach (Vector2Int coord in ship.deckCoords)
|
|
{
|
|
if ((coord.x != x || coord.y != y) && pole.PoleShot[coord.x, coord.y] == 0)
|
|
{
|
|
if (!targetShipCoords.Contains(coord))
|
|
targetShipCoords.Enqueue(coord);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|