示例#1
0
        public ConnectivityMap GenerateConnectivityMapNoCycles(int numberNodes, double branchingRatio)
        {
            var map = new ConnectivityMap();

            var terminalNodes = new HashSet<int> { 0, 1 };
            var nextNodeIndex = 2;

            map.AddRoomConnection(0, 1);

            while(nextNodeIndex < numberNodes) {
                var randomChance = rand.NextDouble();

                int sourceVertex;

                if(randomChance < branchingRatio) {
                    sourceVertex = rand.Next(nextNodeIndex);
                }
                else {
                    sourceVertex = terminalNodes.RandomElementUsing(rand);
                }

                map.AddRoomConnection(sourceVertex, nextNodeIndex);
                terminalNodes.Remove(sourceVertex);
                terminalNodes.Add(nextNodeIndex);
                nextNodeIndex++;
            }

            return map;
        }
示例#2
0
 public void AddAllConnections(ConnectivityMap originMap)
 {
     foreach (var connection in originMap.GetAllConnections())
     {
         AddRoomConnection(connection.Source, connection.Target);
     }
 }
示例#3
0
 public void AddAllConnections(ConnectivityMap originMap)
 {
     foreach (var connection in originMap.GetAllConnections())
     {
         AddRoomConnection(connection.Source, connection.Target);
     }
 }
        public void MapCycleReducerMapsContainsAMappingForEachEdgeInReducedMap()
        {
            //Build a graph with one nested cycles

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(4, 5);
            newMap.AddRoomConnection(3, 5);

            //Exterior connections

            newMap.AddRoomConnection(5, 6);
            newMap.AddRoomConnection(4, 7);
            newMap.AddRoomConnection(4, 8);
            newMap.AddRoomConnection(3, 9);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            Assert.AreEqual(6, cycleReducer.edgeMappingNoCycleToFullMap.Count());
        }
示例#5
0
        public void AddingSameEdgeTwiceDoesntMakeTwoEdges()
        {
            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(1, 2);

            Assert.AreEqual(1, newMap.RoomConnectionGraph.EdgeCount);
        }
        public void DoesNotContainEdgeNotInMap()
        {
            //Build a simple graph

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);
            newMap.AddRoomConnection(3, 4);

            newMap.GetEdgeBetweenRooms(2, 4);
        }
示例#7
0
        public MapInfo(MapInfoBuilder builder)
        {
            rooms = builder.Rooms;
            roomToLevelMapping = builder.RoomLevelMapping;
            map = builder.FullConnectivityMap;
            startRoom = builder.StartRoom;
            doors = builder.Doors;

            model = new MapModel(map, startRoom);

            BuildRoomIndices();
        }
示例#8
0
        public void CyclesOnSeparateLevelsCanBeReturned()
        {
            var builder = new MapInfoBuilder();

            var l1ConnectivityMap = new ConnectivityMap();

            //Cycle in level 1
            l1ConnectivityMap.AddRoomConnection(1, 2);
            l1ConnectivityMap.AddRoomConnection(2, 3);
            l1ConnectivityMap.AddRoomConnection(3, 1);

            var l1RoomList = new List<TemplatePositioned>();
            var room1 = new TemplatePositioned(1, 1, 0, null, 1);
            l1RoomList.Add(room1);
            l1RoomList.Add(new TemplatePositioned(1, 1, 0, null, 2));
            l1RoomList.Add(new TemplatePositioned(1, 1, 0, null, 3));

            var l2ConnectivityMap = new ConnectivityMap();

            //Cycle in level 2
            l2ConnectivityMap.AddRoomConnection(5, 6);
            l2ConnectivityMap.AddRoomConnection(6, 7);
            l2ConnectivityMap.AddRoomConnection(7, 5);

            var l2RoomList = new List<TemplatePositioned>();
            var room5 = new TemplatePositioned(1, 1, 0, null, 5);
            l2RoomList.Add(room5);
            l2RoomList.Add(new TemplatePositioned(1, 1, 0, null, 6));
            l2RoomList.Add(new TemplatePositioned(1, 1, 0, null, 7));

            builder.AddConstructedLevel(0, l1ConnectivityMap, l1RoomList, new Dictionary<Connection, Point>(), 1);
            builder.AddConstructedLevel(1, l2ConnectivityMap, l2RoomList, new Dictionary<Connection, Point>(), new Connection(3, 5));

            var mapInfo = new MapInfo(builder);

            var cyclesOnLevel0 = mapInfo.GetCyclesOnLevel(0).ToList();
            Assert.AreEqual(1, cyclesOnLevel0.Count());
            CollectionAssert.AreEquivalent(cyclesOnLevel0[0], new List<Connection>{
                new Connection(1, 2),
                new Connection(2, 3),
                new Connection(3, 1)
            });

            var cyclesOnLevel1 = mapInfo.GetCyclesOnLevel(1).ToList();
            Assert.AreEqual(1, cyclesOnLevel1.Count());
            CollectionAssert.AreEquivalent(cyclesOnLevel1[0], new List<Connection>{
                new Connection(5, 6),
                new Connection(6, 7),
                new Connection(7, 5)
            });
        }
        public void ContainEdgeInMap()
        {
            //Build a simple graph

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            var edge = newMap.GetEdgeBetweenRooms(1, 2);

            Assert.AreEqual(edge.Source, 1);
            Assert.AreEqual(edge.Target, 2);
        }
        public void ConnectionCanBeAddedFromAnotherMap()
        {
            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            ConnectivityMap newMap2 = new ConnectivityMap();

            newMap2.AddRoomConnection(3, 4);
            newMap2.AddRoomConnection(4, 5);

            newMap.AddAllConnections(newMap2);

            CollectionAssert.AreEquivalent(new List<Connection>(new Connection[] { new Connection(1, 2), new Connection(2, 3),
                new Connection(3, 4), new Connection(4, 5)}), newMap.GetAllConnections().ToList());
        }
示例#11
0
        /// <summary>
        /// Constructed with the inputMap and the room id of the PC start location
        /// </summary>
        /// <param name="inputMap"></param>
        /// <param name="startVertex"></param>
        public MapModel(ConnectivityMap inputMap, int startVertex)
        {
            this.inputMap = inputMap;

            baseGraph        = new UndirectedGraph <int, TaggedEdge <int, string> >();
            this.startVertex = startVertex;

            //Clone the input graph (edges only)
            baseGraph.AddVerticesAndEdgeRange(inputMap.RoomConnectionGraph.Edges);

            //Build cycle-free map
            graphNoCycles = new MapCycleReducer(baseGraph.Edges);

            //Build Door and Clue Manager
            //Ensure we pass on the mapped (to no cycles) version of the start vertex
            doorAndClueManager = new DoorAndClueManager(graphNoCycles, graphNoCycles.roomMappingFullToNoCycleMap[startVertex]);

            //Build a random generator (don't keep instantiating them, because they all give the same number if during the same tick!
            random = new Random();
        }
        public void EdgeTraversingCycleIsInMapAfterCycleReduction()
        {
            //Build a graph with one nested cycle

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(4, 5);
            newMap.AddRoomConnection(3, 5);

            newMap.AddRoomConnection(5, 6);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            Assert.IsTrue(cycleReducer.IsEdgeInRoomsNoCycles(3, 6));
        }
示例#13
0
        public void DeadEndNodesAreFoundInSinglePathGraphs()
        {
            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            var mapNoCycles = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);
            var mapH = new MapHeuristics(mapNoCycles, 1);

            var expectedConnections = new Dictionary<int, List<Connection>> {
                {0, new List<Connection>(new Connection[]{
                    new Connection(1, 2),
                    new Connection(2, 3)})}
            };

            var terminalConnectionsFound = mapH.GetTerminalBranchConnections();

            //TODO: We have slightly pathological behaviour that all non-terminal node connections
            //will be double counted in the
            CollectionAssert.AreEquivalent(expectedConnections[0], terminalConnectionsFound[0]);
            CollectionAssert.AreEquivalent(expectedConnections.Keys, terminalConnectionsFound.Keys);
        }
        public void EdgeBetweenNonCycleAndCycleMapsToBottleneckEdge()
        {
            //Build a graph with one nested cycle

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(4, 5);
            newMap.AddRoomConnection(3, 5);

            newMap.AddRoomConnection(5, 6);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            //In the reduced graph, we have the edge between the first node of the cycle and the next node
            //In the full graph, we have the bottleneck edge between the cycle and the next node

            Assert.AreEqual(cycleReducer.edgeMappingNoCycleToFullMap[new Connection(3, 6)], new Connection(5, 6));
        }
示例#15
0
        private ConnectivityMap BuildStandardTestMap()
        {
            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Branch

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(3, 5);
            newMap.AddRoomConnection(5, 6);

            //Cycle

            newMap.AddRoomConnection(2, 8);
            newMap.AddRoomConnection(2, 7);
            newMap.AddRoomConnection(8, 9);
            newMap.AddRoomConnection(7, 9);

            //Post-cycle

            newMap.AddRoomConnection(9, 10);
            newMap.AddRoomConnection(10, 11);
            newMap.AddRoomConnection(11, 12);
            newMap.AddRoomConnection(11, 13);

            //2-way branches
            newMap.AddRoomConnection(13, 14);
            newMap.AddRoomConnection(13, 15);

            //Save to disk
            GraphvizExport.OutputUndirectedGraph(newMap.RoomConnectionGraph, "standard-test-map");

            return newMap;
        }
        public void MapCycleReducerMapsNonReducedNodeBackToThemselves()
        {
            //Build a graph with one nested cycles

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(4, 5);
            newMap.AddRoomConnection(3, 5);

            newMap.AddRoomConnection(5, 6);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            var roomMapping = cycleReducer.roomMappingNoCycleToFullMap;

            //Confirm that all the first node in the cycle maps back to all the collapsed nodes
            CollectionAssert.AreEquivalent(new List<int>(new int[] { 1 }), roomMapping[1]);
            CollectionAssert.AreEquivalent(new List<int>(new int[] { 2 }), roomMapping[2]);
            CollectionAssert.AreEquivalent(new List<int>(new int[] { 6 }), roomMapping[6]);
        }
 private Connection GetRandomEdgeInMap(ConnectivityMap generatedMap)
 {
     return generatedMap.GetAllConnections().RandomElementUsing(random);
 }
        public void MapCycleReducerRemovesMultipleCyclesInInputMap()
        {
            //Build a graph with one two nested cycles

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(4, 5);
            newMap.AddRoomConnection(3, 5);

            newMap.AddRoomConnection(5, 6);

            //Cycle

            newMap.AddRoomConnection(6, 7);
            newMap.AddRoomConnection(7, 8);
            newMap.AddRoomConnection(8, 9);
            newMap.AddRoomConnection(9, 10);
            newMap.AddRoomConnection(10, 11);
            newMap.AddRoomConnection(11, 6);
            newMap.AddRoomConnection(9, 6);

            newMap.AddRoomConnection(11, 12);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            var roomMapping = cycleReducer.roomMappingFullToNoCycleMap;

            //Confirm that all the first cycle nodes are mapped to the first node in the cycle
            Assert.AreEqual(3, roomMapping[3]);
            Assert.AreEqual(3, roomMapping[4]);
            Assert.AreEqual(3, roomMapping[5]);

            //Confirm that all the second cycle nodes are mapped to the first node in the second cycle
            Assert.AreEqual(6, roomMapping[6]);
            Assert.AreEqual(6, roomMapping[7]);
            Assert.AreEqual(6, roomMapping[8]);
            Assert.AreEqual(6, roomMapping[9]);
            Assert.AreEqual(6, roomMapping[10]);
            Assert.AreEqual(6, roomMapping[11]);
        }
        public void MapCycleReducerMapsReducedCycleNodeBackToOriginalNodes()
        {
            //Build a graph with one nested cycles

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(4, 5);
            newMap.AddRoomConnection(3, 5);

            newMap.AddRoomConnection(5, 6);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            var roomMapping = cycleReducer.roomMappingNoCycleToFullMap;

            //Confirm that all the first node in the cycle maps back to all the collapsed nodes
            CollectionAssert.AreEquivalent(new List<int>{ 3, 4, 5 }, roomMapping[3]);
        }
示例#20
0
        public void MapsFromDifferentLevelsCanBeConnected()
        {
            var mapInfo = new MapInfoBuilder();

            var l1ConnectivityMap = new ConnectivityMap();
            l1ConnectivityMap.AddRoomConnection(1, 2);
            l1ConnectivityMap.AddRoomConnection(2, 3);

            var l2ConnectivityMap = new ConnectivityMap();
            l2ConnectivityMap.AddRoomConnection(5, 6);
            l2ConnectivityMap.AddRoomConnection(6, 7);

            mapInfo.AddConstructedLevel(0, l1ConnectivityMap, new List<TemplatePositioned>(), new Dictionary<Connection, Point>(), 0);
            mapInfo.AddConstructedLevel(1, l2ConnectivityMap, new List<TemplatePositioned>(), new Dictionary<Connection, Point>(), new Connection(3, 5));

            ConnectivityMap fullMap = mapInfo.FullConnectivityMap;

            CollectionAssert.AreEquivalent(new List<Connection>(new Connection[] { new Connection(1, 2), new Connection(2, 3),
                new Connection(3, 5), new Connection(5, 6), new Connection(6, 7)}), fullMap.GetAllConnections().ToList());
        }
        public void CluesCanBePlacedInRoomIfOnlyOneRoomPossible()
        {
            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);

            var mapNoCycles = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);
            var mapMST = new MapMST(mapNoCycles.mapNoCycles.Edges);
            var manager = new DoorAndClueManager(mapNoCycles, 1);

            Assert.IsNotNull(manager.PlaceDoorAndClue(new DoorRequirements(new Connection(1, 2), "lock0"), 1));
        }
示例#22
0
        private MapInfoBuilder GetStandardMapInfoBuilderForTemplates()
        {
            var builder = new MapInfoBuilder();

            var l1ConnectivityMap = new ConnectivityMap();
            l1ConnectivityMap.AddRoomConnection(1, 2);
            l1ConnectivityMap.AddRoomConnection(2, 3);

            var corridor1 = new RoomTemplateTerrain[1,3];
            var corridor2 = new RoomTemplateTerrain[3, 1];
            var room1 = new RoomTemplateTerrain[4, 4];

            var l1RoomList = new List<TemplatePositioned>();
            l1RoomList.Add(new TemplatePositioned(1, 1, 0, new RoomTemplate(corridor1), 0));
            l1RoomList.Add(new TemplatePositioned(1, 1, 0, new RoomTemplate(corridor2), 1));
            l1RoomList.Add(new TemplatePositioned(1, 1, 0, new RoomTemplate(room1), 2));

            var l1DoorDict = new Dictionary<Connection, Point>();
            l1DoorDict.Add(new Connection(2, 3), new Point(5, 5));

            builder.AddConstructedLevel(0, l1ConnectivityMap, l1RoomList, l1DoorDict, 1);

            return builder;
        }
        public void RemovedEdgeNotFoundInMapCycleReducer()
        {
            //Build a graph with one nested cycle

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(4, 5);
            newMap.AddRoomConnection(3, 5);

            newMap.AddRoomConnection(5, 6);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            cycleReducer.GetEdgeBetweenRoomsNoCycles(4, 5);
        }
示例#24
0
        public void RoomsCanBeRetrievedByIndex()
        {
            var newTemplate = new TemplatePositioned(9, 9, 0, null, 100);
            var mapInfoBuilder = new MapInfoBuilder();

            var templateList = new List<TemplatePositioned>();
            templateList.Add(newTemplate);

            var map = new ConnectivityMap();
            map.AddRoomConnection(new Connection(100, 101));

            mapInfoBuilder.AddConstructedLevel(0, map, templateList, new Dictionary<Connection, Point>(), 100);

            var mapInfo = new MapInfo(mapInfoBuilder);

            Assert.AreEqual(new Point(9,9), mapInfo.GetRoom(100).Location);
        }
示例#25
0
        private MapInfoBuilder GetStandardMapInfoBuilder()
        {
            var builder = new MapInfoBuilder();

            var l1ConnectivityMap = new ConnectivityMap();
            l1ConnectivityMap.AddRoomConnection(1, 2);
            l1ConnectivityMap.AddRoomConnection(2, 3);

            var l1RoomList = new List<TemplatePositioned>();
            var room1 = new TemplatePositioned(1, 1, 0, null, 1);
            l1RoomList.Add(room1);
            l1RoomList.Add(new TemplatePositioned(1, 1, 0, null, 2));
            l1RoomList.Add(new TemplatePositioned(1, 1, 0, null, 3));

            var l2ConnectivityMap = new ConnectivityMap();
            l2ConnectivityMap.AddRoomConnection(5, 6);
            l2ConnectivityMap.AddRoomConnection(6, 7);

            var l2RoomList = new List<TemplatePositioned>();
            var room5 = new TemplatePositioned(1, 1, 0, null, 5);
            l2RoomList.Add(room5);
            l2RoomList.Add(new TemplatePositioned(1, 1, 0, null, 6));
            l2RoomList.Add(new TemplatePositioned(1, 1, 0, null, 7));

            var l1DoorDict = new Dictionary<Connection, Point>();
            l1DoorDict.Add(new Connection(2, 3), new Point(5,5));

            var l2DoorDict = new Dictionary<Connection, Point>();
            l2DoorDict.Add(new Connection(5, 6), new Point(8, 8));

            builder.AddConstructedLevel(0, l1ConnectivityMap, l1RoomList, l1DoorDict, 1);
            builder.AddConstructedLevel(1, l2ConnectivityMap, l2RoomList, l2DoorDict, new Connection(3, 5));

            return builder;
        }
示例#26
0
        public Map GenerateMap(int extraConnections)
        {
            LogFile.Log.LogEntry(String.Format("Generating BSP dungeon"));

            do
            {
                baseMap = new Map(width, height);
                connectivityGraph = new ConnectivityMap();

                //BSP is always connected
                baseMap.GuaranteedConnected = true;

                //Make a BSP tree for the rooms

                rootNode = new MapNode(this, 0, 0, width, height);
                rootNode.Split();

                //Draw a room in each BSP leaf
                rootNode.DrawRoomAtLeaf(baseMap);

                //debug
                //Screen.Instance.DrawMapDebug(baseMap);

                //Draw connecting corridors
                rootNode.DrawCorridorConnectingChildren(baseMap);

                //Add any extra connecting corridors as specified

                for (int i = 0; i < extraConnections; i++)
                {
                    rootNode.AddRandomConnection(baseMap);
                }

                //Add doors where single corridors terminate into rooms
                AddDoorsGraph();

                //Turn corridors into normal squares and surround with walls
                CorridorsIntoRooms();

                //Work out where the staircases will be

                //We just want 2 places that aren't too close to each other. The map is guaranteed connected
                double RequiredStairDistance = (width * 0.5);
                double stairDistance;

                do
                {
                    upStaircase = RandomWalkablePoint();
                    downStaircase = RandomWalkablePoint();

                    stairDistance = Math.Sqrt(Math.Pow(upStaircase.x - downStaircase.x, 2) + Math.Pow(upStaircase.y - downStaircase.y, 2));

                } while (stairDistance < RequiredStairDistance);

                //Set which squares are light blocking
                //Now done during creation
                //SetLightBlocking(baseMap);

                //Set the PC start location in a random room
                baseMap.PCStartLocation = AddEntryRoomForPlayer();

            } while (baseMap.PCStartLocation == null);

            //Fake a start room
                PointInRoom randomRoom = RandomPointInRoom();
                //baseMap.PCStartLocation = randomRoom.GetPointInRoomOnly();
                baseMap.PCStartRoomId = randomRoom.RoomId;

            //Build the map model for the graph, based on the PC's true starting position (useful for locking doors)
            graphModel = new MapModel(connectivityGraph, baseMap.PCStartRoomId);

            //Save out the graph
            GraphvizExport.OutputUndirectedGraph(connectivityGraph.RoomConnectionGraph, "bsptree-base");
            //Save out a copy of the graph with no cycles

            GraphvizExport.OutputUndirectedGraph(graphModel.GraphNoCycles.mapNoCycles, "bsptree-nocycles");

            return baseMap.Clone();
        }
        public void MapWithTwoNestedCyclesGivesCorrectTwoCyclesInAllCycles()
        {
            //Build a graph with one nested cycle

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle 1
            newMap.AddRoomConnection(3, 5);
            newMap.AddRoomConnection(5, 4);
            newMap.AddRoomConnection(4, 3);

            //Nested cycle
            newMap.AddRoomConnection(4, 6);
            newMap.AddRoomConnection(5, 6);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            //Relying on the fact that the DFS hits 3,5 first
            var allCycles = cycleReducer.AllCycles;
            var expectedCycles = new List<List<Connection>> {
                new List<Connection> {
                    new Connection(3,5),
                    new Connection(5,4),
                    new Connection(4,3)
                },
                new List<Connection> {
                    new Connection(4,6),
                    new Connection(6,5),
                    new Connection(5,4)
                }
            };
            Assert.AreEqual(2, allCycles.Count);
            CollectionAssert.AreEquivalent(expectedCycles[0], allCycles[0]);
            CollectionAssert.AreEquivalent(expectedCycles[1], allCycles[1]);
        }
        public void MapWithTwoNonConnectedCyclesGivesTwoCyclesInAllCycles()
        {
            //Build a graph with one nested cycle

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle 1

            newMap.AddRoomConnection(3, 5);
            newMap.AddRoomConnection(5, 4);
            newMap.AddRoomConnection(4, 3);

            newMap.AddRoomConnection(5, 6);

            //Cycle 2

            newMap.AddRoomConnection(6, 7);
            newMap.AddRoomConnection(7, 8);
            newMap.AddRoomConnection(8, 6);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            var allCycles = cycleReducer.AllCycles;

            Assert.AreEqual(2, allCycles.Count);
        }
        public void MapCycleReducerMapsExterorEdgesOfCycleToOriginalConnections()
        {
            //Build a graph with one nested cycles

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(4, 5);
            newMap.AddRoomConnection(3, 5);

            //Exterior connections

            newMap.AddRoomConnection(5, 6);
            newMap.AddRoomConnection(4, 7);
            newMap.AddRoomConnection(4, 8);
            newMap.AddRoomConnection(3, 9);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            var edgeMapping = cycleReducer.edgeMappingNoCycleToFullMap;

            //Exterior connections from start node
            Assert.AreEqual(new Connection(2, 3), edgeMapping[new Connection(2, 3)].Ordered);
            Assert.AreEqual(new Connection(3, 9), edgeMapping[new Connection(3, 9)].Ordered);

            //Exterior connections from collasped nodes
            Assert.AreEqual(new Connection(4, 7), edgeMapping[new Connection(3, 7)].Ordered);
            Assert.AreEqual(new Connection(4, 8), edgeMapping[new Connection(3, 8)].Ordered);

            Assert.AreEqual(new Connection(5, 6), edgeMapping[new Connection(3, 6)].Ordered);
        }
        public void MapCycleReducerRemovesOneCycleInInputMap()
        {
            //Build a graph with one nested cycle

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(4, 5);
            newMap.AddRoomConnection(3, 5);

            newMap.AddRoomConnection(5, 6);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            var roomMapping = cycleReducer.roomMappingFullToNoCycleMap;

            //Confirm that all the cycle nodes are mapped to the first node
            Assert.AreEqual(roomMapping[3], 3);
            Assert.AreEqual(roomMapping[4], 3);
            Assert.AreEqual(roomMapping[5], 3);
        }
        public void MapCycleReducerMapsContainsCorrectMappingForUnchangedEdgesInReducedMap()
        {
            //Build a graph with one nested cycles

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 4);
            newMap.AddRoomConnection(4, 5);
            newMap.AddRoomConnection(3, 5);

            //Exterior connections

            newMap.AddRoomConnection(5, 6);
            newMap.AddRoomConnection(6, 7);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);
            var edgeMapping = cycleReducer.edgeMappingNoCycleToFullMap;

            Assert.AreEqual(new Connection(1, 2), edgeMapping[new Connection(1, 2)].Ordered);
            Assert.AreEqual(new Connection(2, 3), edgeMapping[new Connection(2, 3)].Ordered);
            Assert.AreEqual(new Connection(6, 7), edgeMapping[new Connection(6, 7)].Ordered);
        }
        public void SingleCycleInMapCanBeRetrievedWhenCycleSpecifiedInADifferentOrder()
        {
            //Build a graph with one nested cycle

            ConnectivityMap newMap = new ConnectivityMap();

            newMap.AddRoomConnection(1, 2);
            newMap.AddRoomConnection(2, 3);

            //Cycle

            newMap.AddRoomConnection(3, 5);
            newMap.AddRoomConnection(5, 4);
            newMap.AddRoomConnection(4, 3);

            newMap.AddRoomConnection(5, 6);

            MapCycleReducer cycleReducer = new MapCycleReducer(newMap.RoomConnectionGraph.Edges);

            var allCycles = cycleReducer.AllCycles;
            var expectedCycles = new List<List<Connection>> { new List<Connection> {
                new Connection(3,5),
                new Connection(5,4),
                new Connection(4,3)
            }};

            //Can't know whether the list will be returned in 'clockwise' or 'anticlockwise' ordering
            Assert.AreEqual(allCycles.Count, expectedCycles.Count);
            CollectionAssert.AreEquivalent(allCycles[0], expectedCycles[0]);
        }