Beispiel #1
0
        public static void CompareFloorPlans(TestGridFloorPlan floorPlan, TestGridFloorPlan compareFloorPlan)
        {
            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(compareFloorPlan.RoomCount));
            for (int ii = 0; ii < floorPlan.RoomCount; ii++)
            {
                GridRoomPlan plan        = floorPlan.GetRoomPlan(ii);
                GridRoomPlan comparePlan = compareFloorPlan.GetRoomPlan(ii);
                Assert.That(plan.RoomGen, Is.EqualTo(comparePlan.RoomGen));
                Assert.That(plan.Bounds, Is.EqualTo(comparePlan.Bounds));
            }

            // check positions
            Assert.That(floorPlan.PublicRooms, Is.EqualTo(compareFloorPlan.PublicRooms));
            Assert.That(floorPlan.PublicVHalls.Length, Is.EqualTo(compareFloorPlan.PublicVHalls.Length));
            for (int xx = 0; xx < floorPlan.PublicVHalls.Length; xx++)
            {
                Assert.That(floorPlan.PublicVHalls[xx].Length, Is.EqualTo(compareFloorPlan.PublicVHalls[xx].Length));
                for (int yy = 0; yy < floorPlan.PublicVHalls[xx].Length; yy++)
                {
                    Assert.That(floorPlan.PublicVHalls[xx][yy].Gens, Is.EqualTo(compareFloorPlan.PublicVHalls[xx][yy].Gens));
                }
            }

            Assert.That(floorPlan.PublicHHalls.Length, Is.EqualTo(compareFloorPlan.PublicHHalls.Length));
            for (int xx = 0; xx < floorPlan.PublicHHalls.Length; xx++)
            {
                Assert.That(floorPlan.PublicHHalls[xx].Length, Is.EqualTo(compareFloorPlan.PublicHHalls[xx].Length));
                for (int yy = 0; yy < floorPlan.PublicVHalls[xx].Length; yy++)
                {
                    Assert.That(floorPlan.PublicHHalls[xx][yy].Gens, Is.EqualTo(compareFloorPlan.PublicHHalls[xx][yy].Gens));
                }
            }
        }
Beispiel #2
0
        public void Immutable100Percent()
        {
            string[] inGrid =
            {
                "0.0.0.0.0.0.0",
                ". . . . . . .",
                "0.A#B#C#D#E.0",
                ". . . . . . .",
                "0.0.0.0.0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            GridRoomPlan      roomPlan  = floorPlan.GetRoomPlan(2);

            roomPlan.Immutable = true;

            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            testRand.Setup(p => p.Next(100, 100)).Returns(100);
            testRand.Setup(p => p.Next(It.IsAny <int>())).Returns(0);

            var pathGen = new AddGridDefaultsStep <IGridPathTestContext> {
                DefaultRatio = new RandRange(100)
            };

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(5));
            Assert.That(floorPlan.GetRoomPlan(0).RoomGen, Is.TypeOf <TestGridRoomGen>());
            Assert.That(floorPlan.GetRoomPlan(1).RoomGen, Is.TypeOf <RoomGenDefault <IGridPathTestContext> >());
            Assert.That(floorPlan.GetRoomPlan(2).RoomGen, Is.TypeOf <TestGridRoomGen>());
            Assert.That(floorPlan.GetRoomPlan(3).RoomGen, Is.TypeOf <RoomGenDefault <IGridPathTestContext> >());
            Assert.That(floorPlan.GetRoomPlan(4).RoomGen, Is.TypeOf <TestGridRoomGen>());
        }
Beispiel #3
0
        public void PlaceRoom(int roll, int expectedChosen)
        {
            // verify rand is working
            // place on a floor where the first room is immutable
            // place on a floor where the first room is default
            string[] inGrid =
            {
                "0.0.0.0.0.0.0",
                ". . . . . . .",
                "0.A#B#C#D#E.0",
                ". . . . . . .",
                "0.0.0.0.0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            GridRoomPlan      roomPlan  = floorPlan.GetRoomPlan(1);

            roomPlan.Components.Set(new TestComponent());
            roomPlan            = floorPlan.GetRoomPlan(3);
            roomPlan.RoomGen    = new RoomGenDefault <IGridPathTestContext>();
            roomPlan.PreferHall = true;

            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            // The roll for size
            testRand.Setup(p => p.Next(0, 0)).Returns(0);

            // The roll for choosing room index
            testRand.Setup(p => p.Next(3)).Returns(roll);

            var pathGen = new SetGridSpecialRoomStep <IGridPathTestContext>
            {
                Rooms = new PresetPicker <RoomGen <IGridPathTestContext> >(new RoomGenSquare <IGridPathTestContext>()),
            };

            pathGen.Filters.Add(new RoomFilterComponent(true, new TestComponent()));

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(5));
            for (int ii = 0; ii < 5; ii++)
            {
                if (ii == expectedChosen)
                {
                    Assert.That(floorPlan.GetRoomPlan(ii).RoomGen, Is.TypeOf <RoomGenSquare <IGridPathTestContext> >());
                }
                else
                {
                    Assert.That(floorPlan.GetRoomPlan(ii).RoomGen, Is.Not.TypeOf <RoomGenSquare <IGridPathTestContext> >());
                }
            }
        }
Beispiel #4
0
 public override void ApplyToPath(IRandom rand, GridPlan floorPlan)
 {
     for (int ii = 0; ii < floorPlan.RoomCount; ii++)
     {
         GridRoomPlan plan = floorPlan.GetRoomPlan(ii);
         if (!BaseRoomFilter.PassesAllFilters(plan, this.Filters))
         {
             continue;
         }
         if (plan.RoomGen is IPermissiveRoomGen)
         {
             plan.PreferHall = true;
         }
     }
 }
        private bool roomViable(GridPlan floorPlan, int xx, int yy)
        {
            //must be PRESENT, SINGLE and immutable
            GridRoomPlan plan = floorPlan.GetRoomPlan(new Loc(xx, yy));

            if (plan == null)
            {
                return(false);
            }
            if (plan.Bounds.Area > 1)
            {
                return(false);
            }
            if (!BaseRoomFilter.PassesAllFilters(plan, this.Filters))
            {
                return(false);
            }

            return(true);
        }
Beispiel #6
0
        public void PlaceRoomImpossible()
        {
            // verify rand is working
            // place on a floor where the first room is immutable
            // place on a floor where the first room is default
            string[] inGrid =
            {
                "0.0.0.0.0",
                ". . . . .",
                "0.A#B#C.0",
                ". . . . .",
                "0.0.0.0.0",
            };

            TestGridFloorPlan floorPlan = TestGridFloorPlan.InitGridToContext(inGrid);
            GridRoomPlan      roomPlan  = floorPlan.GetRoomPlan(0);

            roomPlan.Immutable = true;
            roomPlan           = floorPlan.GetRoomPlan(1);
            roomPlan.Immutable = true;
            roomPlan           = floorPlan.GetRoomPlan(2);
            roomPlan.Immutable = true;

            Mock <IRandom> testRand = new Mock <IRandom>(MockBehavior.Strict);

            var pathGen = new AddGridSpecialRoomStep <IGridPathTestContext>
            {
                Rooms = new PresetPicker <RoomGen <IGridPathTestContext> >(new RoomGenSquare <IGridPathTestContext>()),
            };

            pathGen.ApplyToPath(testRand.Object, floorPlan);

            // check the rooms
            Assert.That(floorPlan.RoomCount, Is.EqualTo(3));
            for (int ii = 0; ii < 3; ii++)
            {
                Assert.That(floorPlan.GetRoomPlan(ii).RoomGen, Is.TypeOf <TestGridRoomGen>());
            }
        }
Beispiel #7
0
 private bool spaceViable(GridPlan floorPlan, Rect rect)
 {
     //all tiles must be ABSENT, or SINGLE AND not immutable
     for (int xx = rect.Start.X; xx < rect.End.X; xx++)
     {
         for (int yy = rect.Start.Y; yy < rect.End.Y; yy++)
         {
             GridRoomPlan plan = floorPlan.GetRoomPlan(new Loc(xx, yy));
             if (plan == null)
             {
                 continue;
             }
             if (plan.Bounds.Area > 1)
             {
                 return(false);
             }
             if (!BaseRoomFilter.PassesAllFilters(plan, this.Filters))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #8
0
        public static ConsoleKey PrintGridRoomHalls(IGenContext map, string msg, bool printDebug, bool printViewer)
        {
            IRoomGridGenContext context = map as IRoomGridGenContext;

            if (context == null)
            {
                return(ConsoleKey.Enter);
            }

            StringBuilder str  = new StringBuilder();
            GridPlan      plan = context.GridPlan;

            if (plan == null)
            {
                return(ConsoleKey.Enter);
            }

            for (int yy = 0; yy < plan.GridHeight; yy++)
            {
                if (yy > 0)
                {
                    str.Append('\n');
                }

                for (int xx = 0; xx < plan.GridWidth; xx++)
                {
                    int roomIndex = plan.GetRoomIndex(new Loc(xx, yy));
                    if (roomIndex == -1)
                    {
                        str.Append('0');
                    }
                    else// if (roomIndex < 26)
                    {
                        str.Append((char)('A' + roomIndex % 26));
                    }
                    //else
                    //    str.Append('@');

                    if (xx < plan.GridWidth - 1)
                    {
                        if (plan.GetHall(new LocRay4(xx, yy, Dir4.Right)) != null)
                        {
                            str.Append('#');
                        }
                        else
                        {
                            str.Append('.');
                        }
                    }
                }

                if (yy < plan.GridHeight - 1)
                {
                    str.Append('\n');
                    for (int xx = 0; xx < plan.GridWidth; xx++)
                    {
                        if (plan.GetHall(new LocRay4(xx, yy, Dir4.Down)) != null)
                        {
                            str.Append('#');
                        }
                        else
                        {
                            str.Append('.');
                        }

                        if (xx < plan.GridWidth - 1)
                        {
                            str.Append(' ');
                        }
                    }
                }
            }


            string newStr = str.ToString();

            if (gridDebugString[currentDepth].MapString == newStr)
            {
                return(ConsoleKey.Enter);
            }

            gridDebugString[currentDepth].MapString = newStr;


            if (printDebug)
            {
                Debug.WriteLine(msg);
                Debug.Print(newStr);
            }

            if (printViewer)
            {
                SteppingIn = false;
                Console.Clear();
                Console.WriteLine(msg);
                Loc start = new Loc(Console.CursorLeft, Console.CursorTop);
                Console.Write(newStr);
                Loc end = new Loc(Console.CursorLeft, Console.CursorTop + 1);
                Console.SetCursorPosition(start.X, start.Y);
                int prevFarthestPrint = end.Y;

                while (true)
                {
                    int farthestPrint = end.Y;
                    Loc gridLoc       = new Loc(Console.CursorLeft, Console.CursorTop) - start;
                    Loc mapLoc        = gridLoc / 2;
                    rewriteLine(farthestPrint, String.Format("X:{0:0.0}  Y:{1:0.0}", ((float)gridLoc.X / 2), ((float)gridLoc.Y / 2)));
                    farthestPrint++;

                    bool alignX = gridLoc.X % 2 == 0;
                    bool alignY = gridLoc.Y % 2 == 0;

                    if (alignX && alignY)
                    {
                        int          index    = plan.GetRoomIndex(mapLoc);
                        GridRoomPlan roomPlan = plan.GetRoomPlan(mapLoc);
                        if (roomPlan != null)
                        {
                            string roomString = String.Format("Room #{0}: {1}", index, roomPlan.RoomGen.ToString());
                            if (roomPlan.PreferHall)
                            {
                                roomString += " [Hall]";
                            }
                            rewriteLine(farthestPrint, roomString);
                            farthestPrint++;
                            string componentString = String.Format("Components: {0}", String.Join(", ", roomPlan.Components));
                            rewriteLine(farthestPrint, componentString);
                            farthestPrint++;
                        }
                    }
                    else if (alignX)
                    {
                        GridHallPlan hall = plan.GetHall(new LocRay4(mapLoc, Dir4.Down));
                        if (hall != null)
                        {
                            rewriteLine(farthestPrint, "Hall: " + hall.RoomGen.ToString());
                            farthestPrint++;
                            string componentString = String.Format("Components: {0}", String.Join(", ", hall.Components));
                            rewriteLine(farthestPrint, componentString);
                            farthestPrint++;
                        }
                    }
                    else if (alignY)
                    {
                        GridHallPlan hall = plan.GetHall(new LocRay4(mapLoc, Dir4.Right));
                        if (hall != null)
                        {
                            rewriteLine(farthestPrint, "Hall: " + hall.RoomGen.ToString());
                            farthestPrint++;
                        }
                    }



                    for (int ii = farthestPrint; ii < prevFarthestPrint; ii++)
                    {
                        clearLine(ii);
                    }
                    prevFarthestPrint = farthestPrint;
                    Console.SetCursorPosition(start.X + gridLoc.X, start.Y + gridLoc.Y);


                    ConsoleKeyInfo key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        Console.SetCursorPosition(Console.CursorLeft, Math.Max(start.Y, Console.CursorTop - 1));
                    }
                    else if (key.Key == ConsoleKey.DownArrow)
                    {
                        Console.SetCursorPosition(Console.CursorLeft, Math.Min(Console.CursorTop + 1, end.Y - 1));
                    }
                    else if (key.Key == ConsoleKey.LeftArrow)
                    {
                        Console.SetCursorPosition(Math.Max(start.X, Console.CursorLeft - 1), Console.CursorTop);
                    }
                    else if (key.Key == ConsoleKey.RightArrow)
                    {
                        Console.SetCursorPosition(Math.Min(Console.CursorLeft + 1, end.X - 1), Console.CursorTop);
                    }
                    else
                    {
                        return(key.Key);
                    }
                }
            }
            else
            {
                return(ConsoleKey.Enter);
            }
        }
Beispiel #9
0
        public static TestGridFloorPlan InitGridToContext(string[] inGrid, int widthPerCell, int heightPerCell)
        {
            // transposes
            if (inGrid.Length % 2 == 0 || inGrid[0].Length % 2 == 0)
            {
                throw new ArgumentException("Bad input grid!");
            }
            var floorPlan = new TestGridFloorPlan();

            floorPlan.InitSize((inGrid[0].Length / 2) + 1, (inGrid.Length / 2) + 1, widthPerCell, heightPerCell);
            GridRoomPlan[] addedRooms = new GridRoomPlan[26];

            for (int xx = 0; xx < inGrid[0].Length; xx++)
            {
                for (int yy = 0; yy < inGrid.Length; yy++)
                {
                    char val = inGrid[yy][xx];
                    int  x   = xx / 2;
                    int  y   = yy / 2;

                    // rooms
                    if (xx % 2 == 0 && yy % 2 == 0)
                    {
                        if (val >= 'A' && val <= 'Z')
                        {
                            floorPlan.Rooms[x][y] = val - 'A';
                            if (addedRooms[val - 'A'] == null)
                            {
                                addedRooms[val - 'A'] = new GridRoomPlan(new Rect(x, y, 1, 1), new TestGridRoomGen(val));
                            }
                            addedRooms[val - 'A'].Bounds = Rect.IncludeLoc(addedRooms[val - 'A'].Bounds, new Loc(x, y));
                        }
                        else if (val == '0')
                        {
                            floorPlan.Rooms[x][y] = -1;
                        }
                        else
                        {
                            throw new ArgumentException($"Bad input grid val at room {x},{y}!");
                        }
                    }
                    else if (xx % 2 == 0 && yy % 2 == 1)
                    {
                        // vhalls
                        if (val == '#')
                        {
                            floorPlan.VHalls[x][y].SetGen(new TestGridRoomGen());
                        }
                        else if (val == '.')
                        {
                            floorPlan.VHalls[x][y].SetGen(null);
                        }
                        else
                        {
                            throw new ArgumentException($"Bad input grid val at vertical hall {x},{y}!");
                        }
                    }
                    else if (xx % 2 == 1 && yy % 2 == 0)
                    {
                        // hhalls
                        if (val == '#')
                        {
                            floorPlan.HHalls[x][y].SetGen(new TestGridRoomGen());
                        }
                        else if (val == '.')
                        {
                            floorPlan.HHalls[x][y].SetGen(null);
                        }
                        else
                        {
                            throw new ArgumentException($"Bad input grid val at horizontal hall {x},{y}!");
                        }
                    }
                    else if (xx % 2 == 1 && yy % 2 == 1)
                    {
                        // blank
                        if (val != ' ')
                        {
                            throw new ArgumentException("Bad input grid val at blank zone!");
                        }
                    }
                }
            }

            for (int ii = 0; ii < 26; ii++)
            {
                if (addedRooms[ii] != null)
                {
                    floorPlan.ArrayRooms.Add(addedRooms[ii]);
                }
            }

            return(floorPlan);
        }
Beispiel #10
0
        public static ConsoleKey PrintGridRoomHalls(IGenContext map, string msg, bool printDebug, bool printViewer)
        {
            if (!(map is IRoomGridGenContext context))
            {
                return(ConsoleKey.Enter);
            }

            var      str  = new StringBuilder();
            GridPlan plan = context.GridPlan;

            if (plan == null)
            {
                return(ConsoleKey.Enter);
            }

            for (int yy = 0; yy < plan.GridHeight; yy++)
            {
                if (yy > 0)
                {
                    str.Append('\n');
                }

                for (int xx = 0; xx < plan.GridWidth; xx++)
                {
                    int roomIndex = plan.GetRoomIndex(new Loc(xx, yy));
                    if (roomIndex == -1)
                    {
                        str.Append('0');
                    }
                    else // if (roomIndex < 26)
                    {
                        str.Append((char)('A' + (roomIndex % 26)));
                    }

                    /* else
                     *     str.Append('@');
                     */

                    if (xx < plan.GridWidth - 1)
                    {
                        if (plan.GetHall(new LocRay4(xx, yy, Dir4.Right)) != null)
                        {
                            str.Append('#');
                        }
                        else
                        {
                            str.Append('.');
                        }
                    }
                }

                if (yy < plan.GridHeight - 1)
                {
                    str.Append('\n');
                    for (int xx = 0; xx < plan.GridWidth; xx++)
                    {
                        if (plan.GetHall(new LocRay4(xx, yy, Dir4.Down)) != null)
                        {
                            str.Append('#');
                        }
                        else
                        {
                            str.Append('.');
                        }

                        if (xx < plan.GridWidth - 1)
                        {
                            str.Append(' ');
                        }
                    }
                }
            }

            string newStr = str.ToString();

            if (gridDebugString[currentDepth].MapString == newStr)
            {
                return(ConsoleKey.Enter);
            }

            gridDebugString[currentDepth].MapString = newStr;

            if (printDebug)
            {
                Debug.WriteLine(msg);
                Debug.Print(newStr);
            }

            if (printViewer)
            {
                SteppingIn = false;
                Console.Clear();
                Console.WriteLine(msg);
                Loc start = new Loc(Console.CursorLeft, Console.CursorTop);
                Console.Write(newStr);
                Loc end = new Loc(Console.CursorLeft, Console.CursorTop + 1);
                Console.SetCursorPosition(start.X, start.Y);
                int prevFarthestPrint = end.Y;

                while (true)
                {
                    int farthestPrint = end.Y;
                    Loc gridLoc       = new Loc(Console.CursorLeft, Console.CursorTop) - start;
                    Loc mapLoc        = gridLoc / 2;
                    RewriteLine(farthestPrint, $"X:{gridLoc.X / 2f:0.0}  Y:{gridLoc.Y / 2f:0.0}");
                    farthestPrint++;

                    bool alignX = gridLoc.X % 2 == 0;
                    bool alignY = gridLoc.Y % 2 == 0;

                    if (alignX && alignY)
                    {
                        int          index    = plan.GetRoomIndex(mapLoc);
                        GridRoomPlan roomPlan = plan.GetRoomPlan(mapLoc);
                        if (roomPlan != null)
                        {
                            string roomString = $"Room #{index}: {roomPlan.RoomGen}";
                            if (roomPlan.Immutable)
                            {
                                roomString += " [Immutable]";
                            }
                            if (roomPlan.PreferHall)
                            {
                                roomString += " [Hall]";
                            }
                            RewriteLine(farthestPrint, roomString);
                            farthestPrint++;
                        }
                    }
                    else if (alignX)
                    {
                        IPermissiveRoomGen hall = plan.GetHall(new LocRay4(mapLoc, Dir4.Down));
                        if (hall != null)
                        {
                            RewriteLine(farthestPrint, "Hall: " + hall);
                            farthestPrint++;
                        }
                    }
                    else if (alignY)
                    {
                        IPermissiveRoomGen hall = plan.GetHall(new LocRay4(mapLoc, Dir4.Right));
                        if (hall != null)
                        {
                            RewriteLine(farthestPrint, "Hall: " + hall);
                            farthestPrint++;
                        }
                    }

                    for (int ii = farthestPrint; ii < prevFarthestPrint; ii++)
                    {
                        ClearLine(ii);
                    }
                    prevFarthestPrint = farthestPrint;
                    Console.SetCursorPosition(start.X + gridLoc.X, start.Y + gridLoc.Y);

                    ConsoleKeyInfo key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.UpArrow)
                    {
                        Console.SetCursorPosition(Console.CursorLeft, Math.Max(start.Y, Console.CursorTop - 1));
                    }
                    else if (key.Key == ConsoleKey.DownArrow)
                    {
                        Console.SetCursorPosition(Console.CursorLeft, Math.Min(Console.CursorTop + 1, end.Y - 1));
                    }
                    else if (key.Key == ConsoleKey.LeftArrow)
                    {
                        Console.SetCursorPosition(Math.Max(start.X, Console.CursorLeft - 1), Console.CursorTop);
                    }
                    else if (key.Key == ConsoleKey.RightArrow)
                    {
                        Console.SetCursorPosition(Math.Min(Console.CursorLeft + 1, end.X - 1), Console.CursorTop);
                    }
                    else
                    {
                        return(key.Key);
                    }
                }
            }
            else
            {
                return(ConsoleKey.Enter);
            }
        }