Beispiel #1
0
        public void AStarNoAssumeWalkable()
        {
            var walkabilityMap = new ArrayMap <bool>(MAP_WIDTH, MAP_HEIGHT);

            RectangleMapGenerator.Generate(walkabilityMap);

            var pather = new AStar(walkabilityMap, Distance.CHEBYSHEV);

            walkabilityMap[START] = false;
            walkabilityMap[END]   = true;

            var path = pather.ShortestPath(START, END, false);

            Assert.AreEqual(false, path != null);

            walkabilityMap[START] = true;
            walkabilityMap[END]   = false;
            path = pather.ShortestPath(START, END, false);
            Assert.AreEqual(false, path != null);

            walkabilityMap[START] = false;
            walkabilityMap[END]   = false;
            path = pather.ShortestPath(START, END, false);
            Assert.AreEqual(false, path != null);

            walkabilityMap[START] = true;
            walkabilityMap[END]   = true;
            path = pather.ShortestPath(START, END, false);
            Assert.AreEqual(true, path != null);
        }
Beispiel #2
0
        // Uhh... this no go here man... Yes this is temp, don't worry.
        private static Map GenerateMap()
        {
            var gennedMap = new Map(MapWidth, MapHeight);

            var walkabilityMap = new ArrayMap <bool>(gennedMap.Width, gennedMap.Height);

            RectangleMapGenerator.Generate(walkabilityMap);

            for (int x = 0; x < walkabilityMap.Width; x++)
            {
                for (int y = 0; y < walkabilityMap.Height; y++)
                {
                    if (walkabilityMap[x, y])
                    {
                        gennedMap.SetTerrain(x, y, new Floor(x, y));
                    }
                    else
                    {
                        gennedMap.SetTerrain(x, y, new Wall(x, y));
                    }
                }
            }

            return(gennedMap);
        }
Beispiel #3
0
        public void PathInitReversing()
        {
            Coord start = Coord.Get(1, 1);
            Coord end   = Coord.Get(6, 6);
            // Because Path constructor is internal to avoid confusion, we use AStar to return a
            // (simple) known path
            var map = new ArrayMap <bool>(10, 10);

            RectangleMapGenerator.Generate(map);
            var pather = new AStar(map, Distance.CHEBYSHEV);

            var actualPath   = pather.ShortestPath(start, end);
            var expectedPath = new List <Coord>();

            for (int i = start.X; i <= end.X; i++)
            {
                expectedPath.Add(Coord.Get(i, i));
            }

            Console.WriteLine("Pre-Reverse:");
            printExpectedAndActual(expectedPath, actualPath);

            checkAgainstPath(expectedPath, actualPath, start, end);

            expectedPath.Reverse();
            actualPath.Reverse();

            Console.WriteLine("\nPost-Reverse:");
            printExpectedAndActual(expectedPath, actualPath);

            checkAgainstPath(expectedPath, actualPath, end, start);
        }
Beispiel #4
0
        public void ViewportBoundingRectangleTest()
        {
            const int VIEWPORT_WIDTH  = 1280 / 12;
            const int VIEWPORT_HEIGHT = 768 / 12;
            const int MAP_WIDTH       = 250;
            const int MAP_HEIGHT      = 250;

            var arrayMap = new ArrayMap <bool>(MAP_WIDTH, MAP_HEIGHT);

            RectangleMapGenerator.Generate(arrayMap);

            var viewport = new Viewport <bool>(arrayMap, new Rectangle(0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT));

            checkViewportBounds(viewport, Coord.Get(0, 0), Coord.Get(VIEWPORT_WIDTH - 1, VIEWPORT_HEIGHT - 1));

            viewport.ViewArea = viewport.ViewArea.Move(Coord.Get(-1, 0)); // Should end up being 0, 0 thanks to bounding
            checkViewportBounds(viewport, Coord.Get(0, 0), Coord.Get(VIEWPORT_WIDTH - 1, VIEWPORT_HEIGHT - 1));

            viewport.ViewArea = viewport.ViewArea.Move(Coord.Get(5, 5));
            checkViewportBounds(viewport, Coord.Get(5, 5), Coord.Get(VIEWPORT_WIDTH - 1 + 5, VIEWPORT_HEIGHT - 1 + 5));

            // Move outside x-bounds by 1
            Coord newCenter = Coord.Get(MAP_WIDTH - (VIEWPORT_WIDTH / 2) + 1, MAP_HEIGHT - (VIEWPORT_HEIGHT / 2) + 1);

            // viewport.ViewArea = viewport.ViewArea.NewWithMinCorner(Coord.Get(250, 100));
            viewport.ViewArea = viewport.ViewArea.CenterOn(newCenter);

            Coord minVal = Coord.Get(MAP_WIDTH - VIEWPORT_WIDTH, MAP_HEIGHT - VIEWPORT_HEIGHT);
            Coord maxVal = Coord.Get(MAP_WIDTH - 1, MAP_HEIGHT - 1);

            checkViewportBounds(viewport, minVal, maxVal);
        }
Beispiel #5
0
        public void LambdaTranslationMapTest()
        {
            ArrayMap <bool> map = new ArrayMap <bool>(10, 10);

            RectangleMapGenerator.Generate(map);

            var lambdaMap = new LambdaTranslationMap <bool, double>(map, b => b ? 1.0 : 0.0);

            checkMaps(map, lambdaMap);
        }
Beispiel #6
0
        public void LambaMapViewTest()
        {
            ArrayMap <bool> map = new ArrayMap <bool>(10, 10);

            RectangleMapGenerator.Generate(map);

            IMapView <double> lambdaMapView = new LambdaMapView <double>(map.Width, map.Height, c => map[c] ? 1.0 : 0.0);

            checkMaps(map, lambdaMapView);
        }
Beispiel #7
0
        public void ManualPrintPath()
        {
            var map = new ArrayMap <bool>(30, 30);

            RectangleMapGenerator.Generate(map);

            var pather = new AStar(map, Distance.MANHATTAN);
            var path   = pather.ShortestPath(1, 2, 5, 6);

            Console.WriteLine(path);
        }
Beispiel #8
0
        public void LambdaSettableTranslationMapTest()
        {
            ArrayMap <double> map = new ArrayMap <double>(10, 10);

            ArrayMap <bool> controlMap = new ArrayMap <bool>(10, 10);

            RectangleMapGenerator.Generate(controlMap);

            var settable = new LambdaSettableTranslationMap <double, bool>(map, d => d > 0.0, b => b ? 1.0 : 0.0);

            RectangleMapGenerator.Generate(settable);

            checkMaps(controlMap, map);
        }
Beispiel #9
0
        public void LambdaSettableMapViewTest()
        {
            ArrayMap <double> map = new ArrayMap <double>(10, 10);

            ArrayMap <bool> controlMap = new ArrayMap <bool>(10, 10);

            RectangleMapGenerator.Generate(controlMap);

            var settable = new LambdaSettableMapView <bool>(map.Width, map.Height, c => map[c] > 0.0, (c, b) => map[c] = b ? 1.0 : 0.0);

            RectangleMapGenerator.Generate(settable);

            checkMaps(controlMap, map);
        }
Beispiel #10
0
        public void ManualPrintFOV()
        {
            var map = new ArrayMap <bool>(10, 10);

            RectangleMapGenerator.Generate(map);
            var resMap = new ResMap(map);

            FOV myFov = new FOV(resMap);

            myFov.Calculate(5, 5, 3);

            Console.WriteLine(myFov);
            Console.WriteLine();
            Console.WriteLine(myFov.ToString(3));
        }
Beispiel #11
0
        public void ManualAStarManhattanTest()
        {
            var map = new ArrayMap <bool>(MAP_WIDTH, MAP_HEIGHT);

            RectangleMapGenerator.Generate(map);

            var pather = new AStar(map, Distance.MANHATTAN);
            var path   = pather.ShortestPath(START, END);

            Utility.PrintHightlightedPoints(map, path.StepsWithStart);

            foreach (var point in path.StepsWithStart)
            {
                Console.WriteLine(point);
            }
        }
Beispiel #12
0
        // Generate basic terrain, no connectivity stuff
        public sealed override void Generate()
        {
            var terrainGen = new ArrayMapOf <bool>(Width, Height);

            RectangleMapGenerator.Generate(terrainGen);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    if (terrainGen[x, y])
                    {
                        Add(new Floor(Coord.Get(x, y)));
                    }
                    else
                    {
                        Add(new Wall(Coord.Get(x, y)));
                    }
                }
            }
        }
Beispiel #13
0
        public void ManualPrintSenseMap()
        {
            var map = new ArrayMap <bool>(30, 30);

            RectangleMapGenerator.Generate(map);

            var resMap   = new ResMap(map);
            var senseMap = new SenseMap(resMap);

            var source  = new SenseSource(SourceType.SHADOW, 12, 15, 10, Radius.CIRCLE);
            var source2 = new SenseSource(SourceType.SHADOW, 18, 15, 10, Radius.CIRCLE);

            senseMap.AddSenseSource(source);
            senseMap.AddSenseSource(source2);

            senseMap.Calculate();

            Console.WriteLine(senseMap);
            Console.WriteLine();
            Console.WriteLine(senseMap.ToString(3));
            Console.WriteLine();
            Console.WriteLine(source);
        }
Beispiel #14
0
        // Use generate here for now, loading can be implemented by another function later in place of generate.
        public sealed override void Generate()
        {
            var terrainGen = new ArrayMapOf <bool>(Width, Height);

            RectangleMapGenerator.Generate(terrainGen);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    if (terrainGen[x, y])
                    {
                        if (SingletonRandom.DefaultRNG.Next(1, 100) > 95)
                        {
                            Add(new Tree(Coord.Get(x, y)));
                        }
                        else
                        {
                            Add(new Floor(Coord.Get(x, y)));
                        }
                    }
                    else
                    {
                        Add(new Wall(Coord.Get(x, y)));
                    }
                }
            }

            SetBackgroundColor(new RLColor(0, .05f, 0)); // Dark green, need to pull this out.

            // Generate enemies
            for (int i = 0; i < 5; i++)
            {
                Coord enemyPos = RandomOpenPosition(this, SingletonRandom.DefaultRNG);
                Add(new PassiveEnemy(enemyPos));
            }
        }
Beispiel #15
0
        public void ManualGoalMapTest()
        {
            var map = new ArrayMap <bool>(MAP_WIDTH, MAP_HEIGHT);

            RectangleMapGenerator.Generate(map);

            var stateMap = new ArrayMap <GoalState>(map.Width, map.Height);

            foreach (var pos in stateMap.Positions())
            {
                stateMap[pos] = map[pos] ? GoalState.Clear : GoalState.Obstacle;
            }

            stateMap[MAP_WIDTH / 2, MAP_WIDTH / 2]          = GoalState.Goal;
            stateMap[MAP_WIDTH / 2 + 5, MAP_HEIGHT / 2 + 5] = GoalState.Goal;

            var goalMap = new GoalMap(stateMap, Distance.EUCLIDEAN);

            goalMap.Update();

            Assert.AreEqual(null, goalMap[0, 0]);

            Console.Write(goalMap.ToString(5, "0.00"));
        }
Beispiel #16
0
        // Generate basic terrain, no connectivity stuff
        public sealed override void Generate()
        {
            var terrainGen = new ArrayMapOf <bool>(Width, Height);

            RectangleMapGenerator.Generate(terrainGen);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    if (terrainGen[x, y])
                    {
                        Add(new Floor(Coord.Get(x, y)));
                    }
                    else
                    {
                        Add(new Wall(Coord.Get(x, y)));
                    }
                }
            }

            // Ooh, we can learn stuff!
            Add(new AltarOfGating(Coord.Get(Width / 2, Height / 2)));
        }