62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class UltimateBotAI : IBotAI
|
|
{
|
|
private List<Vector2Int> knownDeckCoords = new List<Vector2Int>();
|
|
private bool initialized = false;
|
|
|
|
public Vector2Int MakeMove(GamePole pole)
|
|
{
|
|
if (!initialized)
|
|
{
|
|
InitializeCheatKnowledge(pole);
|
|
initialized = true;
|
|
}
|
|
|
|
int totalEnemyShips = 10;
|
|
int remainingEnemyShips = pole.gameManager.enemyShips;
|
|
int shipsLost = totalEnemyShips - remainingEnemyShips;
|
|
|
|
float missChance = Mathf.Clamp01(0.9f - shipsLost * 0.1f);
|
|
bool shouldMiss = Random.value < missChance;
|
|
|
|
if (shouldMiss)
|
|
{
|
|
List<(int x, int y)> emptyShots = pole.GetAvailableShots();
|
|
if (emptyShots.Count > 0)
|
|
{
|
|
var missShot = emptyShots[Random.Range(0, emptyShots.Count)];
|
|
return new Vector2Int(missShot.x, missShot.y);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (Vector2Int coord in knownDeckCoords)
|
|
{
|
|
if (pole.PoleShot[coord.x, coord.y] == 0)
|
|
{
|
|
return coord;
|
|
}
|
|
}
|
|
}
|
|
|
|
return new Vector2Int(-1, -1); // Õîäîâ íåò
|
|
}
|
|
|
|
private void InitializeCheatKnowledge(GamePole pole)
|
|
{
|
|
knownDeckCoords.Clear();
|
|
foreach (var shipObj in pole.GetPlacedShips())
|
|
{
|
|
var ship = shipObj.GetComponent<Ship>();
|
|
if (ship == null) continue;
|
|
|
|
foreach (Vector2Int coord in ship.deckCoords)
|
|
{
|
|
knownDeckCoords.Add(coord);
|
|
}
|
|
}
|
|
}
|
|
}
|