public AiMap(Map.Map map) { Height = map.Height; Width = map.Width; _cells = new AiMapCell[map.Width, map.Height]; // Copy the map into the AI map for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { _cells[x, y] = new AiMapCell(this, x, y, map.Cell(x, y)); } } // Add the possible moves from every cell for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { _cells[x, y].UpdatePossibleDirections(); } } }
public AiMapCell ClosestPill() { var distance = int.MaxValue; AiMapCell closest = null; for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { var cell = _cells[x, y]; var ct = cell.MapCellDetail.CellType; if ((ct == CellType.Pill && !cell.MapCellDetail.PillEaten) && cell.Distance <= distance) { closest = cell; distance = cell.Distance; } } } return(closest); }