private static void InitFloorToContext(TestFloorPlan floorPlan, Rect rect, Rect[] rooms, Rect[] halls, Tuple <char, char>[] links) { floorPlan.InitRect(rect); // a quick way to set up rooms, halls, and connections // a list of rects for rooms, a list of rects for halls for (int ii = 0; ii < rooms.Length; ii++) { var gen = new TestFloorPlanGen((char)('A' + ii)); gen.PrepareDraw(rooms[ii]); floorPlan.PublicRooms.Add(new FloorRoomPlan(gen, new ComponentCollection())); } for (int ii = 0; ii < halls.Length; ii++) { var gen = new TestFloorPlanGen((char)('a' + ii)); gen.PrepareDraw(halls[ii]); floorPlan.PublicHalls.Add(new FloorHallPlan(gen, new ComponentCollection())); } // and finally a list of tuples that link rooms to rooms and halls to halls for (int ii = 0; ii < links.Length; ii++) { bool hall1 = links[ii].Item1 >= 'a'; int index1 = hall1 ? links[ii].Item1 - 'a' : links[ii].Item1 - 'A'; bool hall2 = links[ii].Item2 >= 'a'; int index2 = hall2 ? links[ii].Item2 - 'a' : links[ii].Item2 - 'A'; var link1 = new RoomHallIndex(index1, hall1); var link2 = new RoomHallIndex(index2, hall2); IFloorRoomPlan from1 = floorPlan.GetRoomHall(link1); IFloorRoomPlan from2 = floorPlan.GetRoomHall(link2); from1.Adjacents.Add(link2); from2.Adjacents.Add(link1); } }
public void PlaceRoomMultiAdjacent() { // the new room touches adjacents of two sides of the old room TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext( new Loc(22, 14), new Rect[] { new Rect(3, 3, 6, 6), new Rect(3, 1, 2, 2), new Rect(1, 3, 2, 2) }, Array.Empty <Rect>(), new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C') }); TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext( new Loc(22, 14), new Rect[] { new Rect(3, 1, 2, 2), new Rect(1, 3, 2, 2), new Rect(3, 3, 2, 2) }, Array.Empty <Rect>(), new Tuple <char, char>[] { Tuple.Create('C', 'B'), Tuple.Create('C', 'A') }); ((TestFloorPlanGen)compareFloorPlan.GetRoom(0)).Identifier = 'B'; ((TestFloorPlanGen)compareFloorPlan.GetRoom(1)).Identifier = 'C'; ((TestFloorPlanGen)compareFloorPlan.GetRoom(2)).Identifier = 'D'; Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict); var gen = new TestFloorPlanGen('D'); gen.PrepareDraw(new Rect(3, 3, 2, 2)); var mockRooms = new Mock <IRandPicker <RoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict); var mockHalls = new Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict); var pathGen = new AddSpecialRoomTestStep(mockRooms.Object, mockHalls.Object); pathGen.PlaceRoom(testRand.Object, floorPlan, gen, new RoomHallIndex(0, false)); TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan); }
public void PlaceRoomAllSupport() { // needs a supporting hall for all sides TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext( new Loc(22, 14), new Rect[] { new Rect(3, 3, 6, 6), new Rect(5, 9, 2, 2), new Rect(1, 5, 2, 2), new Rect(5, 1, 2, 2), new Rect(9, 5, 2, 2) }, Array.Empty <Rect>(), new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C'), Tuple.Create('A', 'D'), Tuple.Create('A', 'E') }); TestFloorPlan compareFloorPlan; { var links = new Tuple <char, char>[] { Tuple.Create('E', 'a'), Tuple.Create('E', 'b'), Tuple.Create('E', 'c'), Tuple.Create('E', 'd'), Tuple.Create('a', 'A'), Tuple.Create('b', 'B'), Tuple.Create('c', 'C'), Tuple.Create('d', 'D'), }; compareFloorPlan = TestFloorPlan.InitFloorToContext( new Loc(22, 14), new Rect[] { new Rect(5, 9, 2, 2), new Rect(1, 5, 2, 2), new Rect(5, 1, 2, 2), new Rect(9, 5, 2, 2), new Rect(5, 5, 2, 2) }, new Rect[] { new Rect(5, 7, 2, 2), new Rect(3, 5, 2, 2), new Rect(5, 3, 2, 2), new Rect(7, 5, 2, 2) }, links); } ((TestFloorPlanGen)compareFloorPlan.GetRoom(0)).Identifier = 'B'; ((TestFloorPlanGen)compareFloorPlan.GetRoom(1)).Identifier = 'C'; ((TestFloorPlanGen)compareFloorPlan.GetRoom(2)).Identifier = 'D'; ((TestFloorPlanGen)compareFloorPlan.GetRoom(3)).Identifier = 'E'; ((TestFloorPlanGen)compareFloorPlan.GetRoom(4)).Identifier = 'F'; Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict); var gen = new TestFloorPlanGen('F'); gen.PrepareDraw(new Rect(5, 5, 2, 2)); var mockRooms = new Mock <IRandPicker <RoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict); Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > > mockHalls = new Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict); Moq.Language.ISetupSequentialResult <PermissiveRoomGen <IFloorPlanTestContext> > hallSeq = mockHalls.SetupSequence(p => p.Pick(testRand.Object)); hallSeq = hallSeq.Returns(new TestFloorPlanGen('a')); hallSeq = hallSeq.Returns(new TestFloorPlanGen('b')); hallSeq = hallSeq.Returns(new TestFloorPlanGen('c')); hallSeq = hallSeq.Returns(new TestFloorPlanGen('d')); var pathGen = new AddSpecialRoomTestStep(mockRooms.Object, mockHalls.Object); pathGen.PlaceRoom(testRand.Object, floorPlan, gen, new RoomHallIndex(0, false)); TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan); }
public void PlaceRoomOneSupport() { // needs a supporting hall for one side TestFloorPlan floorPlan = TestFloorPlan.InitFloorToContext( new Loc(22, 14), new Rect[] { new Rect(3, 3, 6, 6), new Rect(5, 1, 2, 2), new Rect(5, 9, 2, 2) }, Array.Empty <Rect>(), new Tuple <char, char>[] { Tuple.Create('A', 'B'), Tuple.Create('A', 'C') }); TestFloorPlan compareFloorPlan = TestFloorPlan.InitFloorToContext( new Loc(22, 14), new Rect[] { new Rect(5, 1, 2, 2), new Rect(5, 9, 2, 2), new Rect(5, 3, 2, 2) }, new Rect[] { new Rect(5, 5, 2, 4) }, new Tuple <char, char>[] { Tuple.Create('C', 'A'), Tuple.Create('C', 'a'), Tuple.Create('a', 'B') }); ((TestFloorPlanGen)compareFloorPlan.GetRoom(0)).Identifier = 'B'; ((TestFloorPlanGen)compareFloorPlan.GetRoom(1)).Identifier = 'C'; ((TestFloorPlanGen)compareFloorPlan.GetRoom(2)).Identifier = 'D'; Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict); var gen = new TestFloorPlanGen('D'); gen.PrepareDraw(new Rect(5, 3, 2, 2)); var mockRooms = new Mock <IRandPicker <RoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict); Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > > mockHalls = new Mock <IRandPicker <PermissiveRoomGen <IFloorPlanTestContext> > >(MockBehavior.Strict); mockHalls.Setup(p => p.Pick(testRand.Object)).Returns(new TestFloorPlanGen('a')); var pathGen = new AddSpecialRoomTestStep(mockRooms.Object, mockHalls.Object); pathGen.PlaceRoom(testRand.Object, floorPlan, gen, new RoomHallIndex(0, false)); TestFloorPlan.CompareFloorPlans(floorPlan, compareFloorPlan); }