using System.Collections.Generic; using AI; using DefaultNamespace.AI; using Units; using UnityEngine; namespace HexFiled { public static class HexManager { public static Dictionary UnitCurrentCell; public static Dictionary> CellByColor; public static Dictionary agents; public static void GetNearestDifferCell(UnitColor color, Queue path) { HexCell end = UnitCurrentCell[color].cell; var itters = 0; while (end.Color == color) { var tmp = end; do { end = tmp.Neighbors[Random.Range(0, 5)]; itters++; } while (end == null && itters < 5); if (itters >= 5) { return; } path.Enqueue(end); } } // public static ( bool hasPath, List field ) HasPath(UnitColor color) // { // var start = UnitCurrentCell[color]; // var end = start; // List neighboursCells = new List(); // while (end.Color == color) // { // neighboursCells.AddRange(end.Neighbors); // neighboursCells.ForEach(cell => // { // if (cell.Color != color) // { // end = cell; // } // }); // } // // List closedList = new List(); // HexCell currentCell = start; // // Stack stackIterators = new Stack(); // stackIterators.Push(currentCell); // // closedList.Add(currentCell); // // // while (stackIterators.Count >= 0) // { // if (currentCell == end) // return (true, null); // // List openList = new List(); // // foreach (var neighbour in currentCell.GetListNeighbours()) // { // if (neighbour == null) // { // return (true, null); // } // // // if (closedList.Contains(neighbour) || neighbour.Color != start.Color) continue; // openList.Add(neighbour); // if (neighbour.GetListNeighbours().Contains(end)) // { // return (true, null); // } // } // // // if (openList.Count > 0) // { // currentCell = openList[Random.Range(0, openList.Count - 1)]; // closedList.Add(currentCell); // stackIterators.Push(currentCell); // } // else // { // if (stackIterators.Count == 0) // { // return (false, closedList); // } // // currentCell = stackIterators.Pop(); // } // // if (currentCell.GetListNeighbours().Contains(end)) // { // return (true, null); // } // } // // return (false, closedList); // } } }