public void CircleRadiusAreaProvider()
        {
            bool[,] radius = new bool[30, 30]; // Initted to false

            var radAProv = new RadiusAreaProvider(Coord.Get(15, 15), 10, Radius.CIRCLE);

            foreach (var pos in radAProv.Positions())
            {
                radius[pos.X, pos.Y] = true;
            }

            for (int y = 0; y < radius.GetLength(1); y++)
            {
                for (int x = 0; x < radius.GetLength(0); x++)
                {
                    if (radius[x, y])
                    {
                        Console.Write("1 ");
                    }
                    else
                    {
                        Console.Write("0 ");
                    }
                }
                Console.WriteLine();
            }

            Assert.AreEqual(true, true);
        }
Example #2
0
        public void ManualPrintRadiusAreaProvider()
        {
            var boundlessAreaProv = new RadiusAreaProvider(5, 4, 10, Radius.CIRCLE);
            var boundedAreaProv   = new RadiusAreaProvider(5, 4, 10, Radius.CIRCLE, new Rectangle(0, 0, 10, 10));

            Console.WriteLine(boundlessAreaProv + " is boundless!");
            Console.WriteLine(boundedAreaProv + " is bounded...");
        }
Example #3
0
        private List <Coord> GetIntersections(Entity entity, AdventureEntity target)
        {
            var moveRange  = entity.Speed / 5;
            var intersects = new List <Coord>();

            foreach (var weaponAttack in entity.CombatActions.OfType <WeaponAttack>())
            {
                var attackRadius = new RadiusAreaProvider(target.Coordinate, weaponAttack.GetRange(), Radius.CIRCLE).CalculatePositions().ToArray();
                var moveRadius   = new RadiusAreaProvider(entity.Coordinate, moveRange, Radius.CIRCLE).CalculatePositions().ToArray();
                var map          = Map.WalkabilityMap;
                intersects.AddRange(from t in attackRadius from coord in moveRadius where coord.X >= 0 && coord.X < map.Width && coord.Y >= 0 && coord.Y < map.Height && map[coord] && coord == t select coord);
            }

            return(intersects);
        }
        public static IList <TEntityType> EntitiesInArea <TEntityType>(this Map map, Coord centerPosition, int radius, bool fieldOfView)
            where TEntityType : IGameObject
        {
            var query = new RadiusAreaProvider(centerPosition, radius, map.DistanceMeasurement)
                        .CalculatePositions()
                        .SelectMany(e => map.GetEntities <TEntityType>(e));

            if (fieldOfView)
            {
                return(query.Where(e => CanSee(map, centerPosition, e.Position)).ToList());
            }
            else
            {
                return(query.ToList());
            }
        }
Example #5
0
        public Coord RandomWalkableTileInCircle(Point origin, int radius)
        {
            // TODO: Move this to different class
            // TODO: Add POV limitations

            List <Coord> circle = new RadiusAreaProvider(origin, radius, Radius.CIRCLE).CalculatePositions().ToList();

            Point newLocation = circle.RandomItem();

            while (!GameLoop.World.CurrentMap.IsTileWalkable(newLocation))
            {
                newLocation = circle.RandomItem();
            }

            return(newLocation);
        }
        public void SquareRadiusArea()
        {
            bool[,] radius = new bool[30, 30]; // Initted to false

            var radAProv = new RadiusAreaProvider(Coord.Get(15, 15), 10, Radius.SQUARE);

            foreach (var pos in radAProv.Positions())
            {
                radius[pos.X, pos.Y] = true;
            }

            for (int y = 0; y < radius.GetLength(1); y++)
            {
                for (int x = 0; x < radius.GetLength(0); x++)
                {
                    if (radius[x, y])
                    {
                        Console.Write("1 ");
                    }
                    else
                    {
                        Console.Write("0 ");
                    }
                }
                Console.WriteLine();
            }

            double maxDistance = 0;

            foreach (var pos in radAProv.Positions())
            {
                double distFromCenter = Distance.CHEBYSHEV.DistanceBetween(Coord.Get(15, 15), pos);
                if (distFromCenter < maxDistance)
                {
                    Assert.Fail("Square radius area provider isn't returning in distance order!");
                }

                maxDistance = Math.Max(maxDistance, distFromCenter);
            }
        }
        private bool testSenseMap(SourceType algorithm, Radius shape)
        {
            var map = rectResMap(MAP_WIDTH, MAP_HEIGHT);

            // Start out at false
            bool[,] radiusMap = new bool[MAP_WIDTH, MAP_HEIGHT];
            bool[,] losMap    = new bool[MAP_WIDTH, MAP_HEIGHT];

            var los         = new SenseMap(map);
            var lightSource = new SenseSource(algorithm, CENTER, RADIUS_LEGNTH, shape);

            los.AddSenseSource(lightSource);
            los.Calculate();

            for (int x = 0; x < MAP_WIDTH; x++)
            {
                for (int y = 0; y < MAP_HEIGHT; y++)
                {
                    if (los[x, y] > 0)
                    {
                        losMap[x, y] = true;
                    }
                }
            }

            var radArea = new RadiusAreaProvider(CENTER, RADIUS_LEGNTH, shape);

            foreach (var pos in radArea.CalculatePositions())
            {
                radiusMap[pos.X, pos.Y] = true;
            }

            Console.WriteLine("Radius Shape: ");
            printArray(radiusMap);

            Console.WriteLine("LOS Shape: ");
            printArray(losMap);

            return(equivalentArrays(radiusMap, losMap));
        }
        public void DiamondRadiusArea()
        {
            bool[,] radius = new bool[30, 30]; // Initted to false

            var radAProv = new RadiusAreaProvider(Coord.Get(15, 15), 10, Radius.DIAMOND);

            foreach (var pos in radAProv.CalculatePositions())
            {
                radius[pos.X, pos.Y] = true;
            }

            for (int y = 0; y < radius.GetLength(1); y++)
            {
                for (int x = 0; x < radius.GetLength(0); x++)
                {
                    if (radius[x, y])
                    {
                        Console.Write("1 ");
                    }
                    else
                    {
                        Console.Write("0 ");
                    }
                }
                Console.WriteLine();
            }

            double maxDistance = 0;

            foreach (var pos in radAProv.CalculatePositions())
            {
                double distFromCenter = Distance.MANHATTAN.Calculate(Coord.Get(15, 15), pos);
                if (distFromCenter < maxDistance)
                {
                    Assert.Fail("Square radius area provider isn't returning in distance order, failed on " + pos + "!");
                }

                maxDistance = Math.Max(maxDistance, distFromCenter);
            }
        }