using System; using System.Collections.Generic; namespace MazeGen { /// /// Tracks one agent's progress through the maze: current room, ordered path history /// (for visualization/backtracking), and O(1) sets for "have I been here" / "have I /// used this exit" checks. Plain C# class - no MonoBehaviour/scene dependency, so it's /// cheap to run many of these (e.g. for future autonomous multi-agent scenarios). /// public class MazeAgent { public readonly string Name; public Room CurrentRoom { get; private set; } public int NewRoomsVisited { get; private set; } private readonly List _path = new List(); private readonly HashSet _visitedRoomIds = new HashSet(); private readonly HashSet _usedExitIds = new HashSet(); public IReadOnlyList PathHistory => _path; public event Action RoomEntered; public event Action ReachedExitRoom; public MazeAgent(string name, Room startRoom) { Name = name; EnterRoom(startRoom, null); } public bool HasVisited(int roomId) => _visitedRoomIds.Contains(roomId); public bool HasUsedExit(Exit exit) => _usedExitIds.Contains(exit.Id); public void EnterRoom(Room room, Exit viaExit) { if (viaExit != null) _usedExitIds.Add(viaExit.Id); if (_visitedRoomIds.Add(room.Id)) NewRoomsVisited++; CurrentRoom = room; _path.Add(room); RoomEntered?.Invoke(room); if (room.Kind == RoomKind.Exit) ReachedExitRoom?.Invoke(room); } } }