예제 #1
0
        public void GlobalSetup()
        {
            var map = new Generator(MapSize, MapSize)
                      .ConfigAndGenerateSafe(gen => gen.AddSteps(DefaultAlgorithms.RectangleMapSteps()))
                      .Context.GetFirst <IGridView <bool> >("WallFloor");

            var goalsBase =
                new LambdaTranslationGridView <bool, GoalState>(map, val => val ? GoalState.Clear : GoalState.Obstacle);

            var singleGoalView = new ArrayView <GoalState>(map.Width, map.Height);

            singleGoalView.ApplyOverlay(goalsBase);
            singleGoalView[map.Bounds().Center] = GoalState.Goal;

            _singleGoalMap = new GoalMap(singleGoalView, DistanceCalc);
            _singleFleeMap = new FleeMap(_singleGoalMap);

            var dualGoalView = new ArrayView <GoalState>(map.Width, map.Height);

            dualGoalView.ApplyOverlay(goalsBase);
            foreach (var rect in dualGoalView.Bounds().BisectVertically())
            {
                dualGoalView[rect.Center] = GoalState.Goal;
            }

            _dualGoalMap = new GoalMap(dualGoalView, DistanceCalc);
            _dualFleeMap = new FleeMap(_dualGoalMap);
        }
예제 #2
0
        public void GlobalSetup()
        {
            var map = new Generator(MapSize, MapSize)
                      .ConfigAndGenerateSafe(gen => gen.AddSteps(DefaultAlgorithms.RectangleMapSteps()))
                      .Context.GetFirst <IGridView <bool> >("WallFloor");

            var goalView = new ArrayView <GoalState>(map.Width, map.Height);

            goalView.ApplyOverlay(pos => map[pos] ? GoalState.Clear : GoalState.Obstacle);
            goalView[map.Bounds().Center] = GoalState.Goal;

            // Create the goal maps used as the desires.  They all use the same goals and weights, which in general is not
            // realistic, but will provide a mathematically solid test base nonetheless.
            var maps = new List <GoalMap>();

            for (int i = 0; i < NumGoalMaps; i++)
            {
                var desireMap = new GoalMap(goalView, DistanceCalc);
                maps.Add(desireMap);
            }

            // Create overall weighted goal map
            _desireMap = new WeightedGoalMap(maps);

            // Pre-calculate the point we'll access
            _threeQuarters = new Point(map.Width, map.Height) * 0.75;
        }
예제 #3
0
        /// <summary>
        /// Computes the entire aggregate goal map and returns it, effectively caching the result.
        /// This may be useful in situations where the goals are shared between many characters and do not change frequently.
        /// </summary>
        public ArrayView <double?> Combine()
        {
            var result = new ArrayView <double?>(Width, Height);

            result.ApplyOverlay(this);

            return(result);
        }
예제 #4
0
        private void CreateSenseMap()
        {
            // Create sense map of rectangular area
            var wallFloor = new Generator(MapSize, MapSize)
                            .ConfigAndGenerateSafe(gen => gen.AddSteps(DefaultAlgorithms.RectangleMapSteps()))
                            .Context.GetFirst <IGridView <bool> >("WallFloor");

            var resMap = new ArrayView <double>(wallFloor.Width, wallFloor.Height);

            resMap.ApplyOverlay(pos => wallFloor[pos] ? 0.0 : 1.0);
            _senseMap = new SenseMap(resMap);
        }
예제 #5
0
        public void ApplyOverlayTest()
        {
            var grid = MockGridViews.RectangleBooleanGrid(_width, _height);

            var duplicateGrid = new ArrayView <bool>(grid.Width, grid.Height);

            duplicateGrid.ApplyOverlay(grid);

            foreach (var pos in grid.Positions())
            {
                Assert.Equal(grid[pos], duplicateGrid[pos]);
            }
        }
예제 #6
0
        private static void CellAutoSmoothingAlgo(ISettableGridView <bool> map, ArrayView <bool> oldMap, bool bigAreaFill)
        {
            // Record current state of the map so we can compare to it to determine nearest walls
            oldMap.ApplyOverlay(map);

            // Iterate over inner square only to avoid messing with outer walls
            foreach (var pos in map.Bounds().Expand(-1, -1).Positions())
            {
                if (CountWallsNear(oldMap, pos, 1) >= 5 || bigAreaFill && CountWallsNear(oldMap, pos, 2) <= 2)
                {
                    map[pos] = false;
                }
                else
                {
                    map[pos] = true;
                }
            }
        }
예제 #7
0
        public void ApplyTerrainOverlay()
        {
            var grMap = new Generator(10, 10)
                        .AddSteps(DefaultAlgorithms.RectangleMapSteps())
                        .Generate()
                        .Context.GetFirstOrDefault <ISettableGridView <bool> >();

            TestUtils.NotNull(grMap);

            // Normally, in this situation, you would just use the ApplyTerrainOverlay function overload that takes
            // a translation function, instead of creating tempMap and translationMap.  But we want to test the other
            // overload so we do it this way only for testing
            var translationMap = new LambdaTranslationGridView <bool, IGameObject>(grMap,
                                                                                   (pos, val) =>
                                                                                   val ?
                                                                                   new GameObject(pos, 0)
                        : new GameObject(pos, 0, true, false));

            // Create map
            var map = new Map(grMap.Width, grMap.Height, 1, Distance.Chebyshev);

            // Create temporary map to record what values are supposed to be
            var tempMap = new ArrayView <IGameObject>(grMap.Width, grMap.Height);

            tempMap.ApplyOverlay(translationMap);

            // Apply overlay
            map.ApplyTerrainOverlay(tempMap);

            // Verify tiles match
            Assert.Equal(grMap.Width, map.Width);
            Assert.Equal(grMap.Height, map.Height);
            foreach (var pos in map.Positions())
            {
                Assert.Equal(tempMap[pos], map.GetTerrainAt(pos));
            }
        }