/// <summary> /// Connects the areas by determining all unique areas on the map given using a <see cref="MapAreaFinder"/>, /// and then, if <paramref name="randomizeOrder"/> is true, performing a Fisher Yates shuffle of that /// list of areas found. It then simply connects areas adjacent to each other in that list, /// using the methods specified to determine points within two areas to connect, and how to /// create the tunnel between the two points. /// </summary> /// <param name="map">The map to connect.</param> /// <param name="adjacencyRule"> /// Method of adjacency to respect when determining map areas. Cannot be diagonal. /// </param> /// <param name="areaConnector"> /// The method to use to determine the points from two areas to make a tunnel between, in /// order to connect those two areas. If null is specified, a <see cref="RandomConnectionPointSelector"/> /// is used, that uses the RNG passed into this function. /// </param> /// <param name="tunnelCreator"> /// The tunnel creation strategy to use. If null is specified, /// <see cref="HorizontalVerticalTunnelCreator"/> that utilizes the RNG passed into this function is used. /// </param> /// <param name="rng">The rng to use. If null is specified, the default rng is assumed.</param> /// <param name="randomizeOrder"> /// Whether or not to randomize which room is connected to which -- if this is set to false, /// they will be conencted in the exact order they are returned from the <see cref="MapAreaFinder"/>. /// </param> static public void Connect(ISettableMapView <bool> map, AdjacencyRule adjacencyRule, IAreaConnectionPointSelector areaConnector = null, ITunnelCreator tunnelCreator = null, IGenerator rng = null, bool randomizeOrder = true) { if (adjacencyRule == AdjacencyRule.DIAGONALS) { throw new System.ArgumentException("Cannot specify diagonal adjacency for map connections.", nameof(adjacencyRule)); } if (rng == null) { rng = SingletonRandom.DefaultRNG; } if (areaConnector == null) { areaConnector = new RandomConnectionPointSelector(rng); } if (tunnelCreator == null) { tunnelCreator = new HorizontalVerticalTunnelCreator(rng); } var areas = MapAreaFinder.MapAreasFor(map, adjacencyRule).ToList(); if (randomizeOrder) { areas.FisherYatesShuffle(rng); } Connect(map, areas, areaConnector, tunnelCreator); }
public void TestCellAutoConnectivityAndEnclosure() { var random = new DotNetRandom(); var map = new ArrayMap <bool>(80, 50); Generators.CellularAutomataGenerator.Generate(map, random, 40, 7, 4); for (int i = 0; i < 500; i++) { Generators.CellularAutomataGenerator.Generate(map, random, 40, 7, 4); // Ensure it's connected var areas = MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList(); Assert.AreEqual(1, areas.Count); // Ensure it's enclosed for (int x = 0; x < map.Width; x++) { Assert.AreEqual(false, map[x, 0]); Assert.AreEqual(false, map[x, map.Height - 1]); } for (int y = 0; y < map.Height; y++) { Assert.AreEqual(false, map[0, y]); Assert.AreEqual(false, map[map.Width - 1, y]); } } }
/// <summary> /// Connects the map given using the algorithm described in the class description. /// </summary> /// <param name="map">The map to connect.</param> /// <param name="distanceCalc">The distance calculation that defines distance/neighbors.</param> /// <param name="areaConnector"> /// The area connection strategy to use. Not all methods function on maps with concave areas /// -- see respective class documentation for details. /// </param> /// /// /// <param name="tunnelCreator"> /// The tunnel creation strategy to use. If null is specified, DirectLineTunnelCreator with /// the distance calculation specified is used. /// </param> static public void Connect(ISettableMapView <bool> map, Distance distanceCalc, IAreaConnectionPointSelector areaConnector = null, ITunnelCreator tunnelCreator = null) { if (areaConnector == null) { areaConnector = new RandomConnectionPointSelector(); } if (tunnelCreator == null) { tunnelCreator = new DirectLineTunnelCreator(distanceCalc); } var areas = MapAreaFinder.MapAreasFor(map, distanceCalc).ToList(); var ds = new DisjointSet(areas.Count); while (ds.Count > 1) // Haven't unioned all sets into one { for (int i = 0; i < areas.Count; i++) { int iClosest = findNearestMapArea(areas, distanceCalc, i, ds); var connectionPoints = areaConnector.SelectConnectionPoints(areas[i], areas[iClosest]); tunnelCreator.CreateTunnel(map, connectionPoints.Item1, connectionPoints.Item2); ds.MakeUnion(i, iClosest); } } }
public void TestTwoAreaRect() { var map = new ArrayMap <bool>(80, 50); Generators.RectangleMapGenerator.Generate(map); for (int y = 0; y < 50; y++) { map[40, y] = false; } var areas = MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList(); Assert.AreEqual(2, areas.Count); }
public void TestSingleAreaRect() { var map = new ArrayMap <bool>(80, 50); Generators.RectangleMapGenerator.Generate(map); var areas = MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList(); foreach (var area in areas) { Console.WriteLine(area.Bounds); } Assert.AreEqual(1, areas.Count); }
public void BasicRoomsMapGenMax() { var map = new ArrayMap <bool>(15, 15); var rooms = BasicRoomsGenerator.Generate(map, new GoRogue.Random.MaxRandom(), 1, 5, 8, 10).ToList(); Assert.AreEqual(1, rooms.Count); Assert.AreEqual(8, rooms[0].Width); Assert.AreEqual(8, rooms[0].Height); var areas = MapAreaFinder.MapAreasFor(map, AdjacencyRule.CARDINALS).ToList(); Assert.AreEqual(1, areas.Count); Assert.AreEqual(8, areas[0].Bounds.Width); Assert.AreEqual(8, areas[0].Bounds.Height); }
public void TestOneRoomAreaRect() { var map = new ArrayMap <bool>(80, 50); QuickGenerators.GenerateRectangleMap(map); for (int y = 0; y < 50; y++) { map[40, y] = false; } map[40, 25] = true; var areas = MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList(); Assert.AreEqual(1, areas.Count); }
public void TestMazeGenConnectivityAndEnclosure() { var map = new ArrayMap <bool>(80, 50); try { var random = new StandardGenerator(); for (int i = 0; i < 1500; i++) { QuickGenerators.GenerateDungeonMazeMap(map, random, minRooms: 10, maxRooms: 20, roomMinSize: 4, roomMaxSize: 15); // Ensure it's connected var areas = MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList(); if (areas.Count != 1) { Console.WriteLine($"Map attempt {i + 1}/500 failed, had {areas.Count} areas: "); displayMapAreas(map, areas); } Assert.AreEqual(1, areas.Count); // Ensure it's enclosed for (int x = 0; x < map.Width; x++) { Assert.AreEqual(false, map[x, 0]); Assert.AreEqual(false, map[x, map.Height - 1]); } for (int y = 0; y < map.Height; y++) { Assert.AreEqual(false, map[0, y]); Assert.AreEqual(false, map[map.Width - 1, y]); } } } catch (Exception e) { Console.WriteLine($"Map attempt failed with exception on map: "); displayMapAreas(map, MapAreaFinder.MapAreasFor(map, Distance.MANHATTAN).ToList()); throw e; } }
/// <summary> /// Trims current small dead-end paths from the given map. /// </summary> /// <param name="map">Map to remove-dead-end paths from.</param> /// <param name="saveDeadEndChance">The chance out of 100 that a given dead end is left alone. Defaults to 0.</param> /// <param name="rng">Rng to use. Defaults to SingletonRandom.DefaultRNG.</param> public static void Trim(ISettableMapView <bool> map, int saveDeadEndChance = 0, IGenerator rng = null) => Trim(map, MapAreaFinder.MapAreasFor(map, AdjacencyRule.CARDINALS), saveDeadEndChance, rng);
/// <summary> /// Connects the given map using the algorithm described in the class description. Map areas /// are automatically determined via MapAreaFinder /// </summary> /// <param name="map">The map to connect.</param> /// <param name="distanceCalc">The distance calculation that defines distance/neighbors.</param> /// <param name="areaConnector"> /// The area connection strategy to use. Not all methods function on maps with concave areas /// -- see respective class documentation for details. /// </param> /// /// /// <param name="tunnelCreator"> /// The tunnel creation strategy to use. If null is specified, DirectLineTunnelCreator with /// the distance calculation specified is used. /// </param> static public void Connect(ISettableMapView <bool> map, Distance distanceCalc, IAreaConnectionPointSelector areaConnector = null, ITunnelCreator tunnelCreator = null) { var areas = MapAreaFinder.MapAreasFor(map, distanceCalc).ToList(); Connect(map, areas, distanceCalc, areaConnector, tunnelCreator); }
public List <Area> GoRogueCurrentAreaFinder() { return(MapAreaFinder.MapAreasFor(_rects, NeighborRule).ToList()); }