Beispiel #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);
        }
        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));
            }
        }
Beispiel #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="transparencyView">
 /// The values used to calculate field of view. Values of true are considered
 /// non-blocking (transparent) to line of sight, while false values are considered
 /// to be blocking.
 /// </param>
 /// <param name="resultView">The view in which FOV calculations are stored.</param>
 protected FOVBase(IGridView <bool> transparencyView, ISettableGridView <double> resultView)
 {
     ResultView        = resultView;
     TransparencyView  = transparencyView;
     BooleanResultView = new LambdaTranslationGridView <double, bool>(ResultView, val => val > 0.0);
 }