public bool Equals(PathToKey other) { return(Equals(KeyPosition, other.KeyPosition) && Distance == other.Distance && DoorMask == other.DoorMask); }
private List <PathToKey> GeneratePaths(Vector2Int startPos, Dictionary <char, Vector2Int> keyLocations, Dictionary <char, Vector2Int> doorLocations, List <List <char> > inputGrid) { List <PathToKey> output = new List <PathToKey>(); Queue <PathToKey> locationsLeft = new Queue <PathToKey>(); HashSet <Vector2Int> visited = new HashSet <Vector2Int>(); locationsLeft.Enqueue(new PathToKey() { KeyPosition = startPos, Distance = 0, DoorMask = 0 }); while (locationsLeft.Count > 0) { PathToKey currentLocation = locationsLeft.Dequeue(); // duplication check if (visited.Contains(currentLocation.KeyPosition)) { continue; } visited.Add(currentLocation.KeyPosition); char c = inputGrid[currentLocation.KeyPosition.Y][currentLocation.KeyPosition.X]; // wall if (c == '#') { continue; } // key if (char.IsLower(c) && currentLocation.Distance > 0) { // output currentLocation.KeyCode = 1 << (c - 'a'); output.Add(currentLocation); } // door (obstacle) else if (char.IsUpper(c)) { currentLocation.DoorMask |= (1 << c - 'A'); } // generate locations around current tile List <Vector2Int> around = Around(currentLocation.KeyPosition); foreach (Vector2Int newPos in around) { locationsLeft.Enqueue(new PathToKey() { Distance = currentLocation.Distance + 1, KeyPosition = newPos, DoorMask = currentLocation.DoorMask, }); } } return(output); }