Exemplo n.º 1
0
        public static ISettableGridView <double> TestResMap(int width, int height)
        {
            var map = new ArrayView <double>(width, height);

            foreach (var pos in map.Positions())
            {
                map[pos] = GlobalRandom.DefaultRNG.NextDouble();
            }

            return(map);
        }
        public static ISettableGridView <double> RandomDoubleGrid(int width, int height)
        {
            var    grid = new ArrayView <double>(width, height);
            Random rng  = new Random();

            foreach (var pos in grid.Positions())
            {
                grid[pos] = rng.NextDouble();
            }

            return(grid);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor. Takes a goal map where in all goals are treated as threats to be avoided,
        /// and a magnitude to use (defaulting to 1.2).
        /// </summary>
        /// <param name="baseMap">The underlying goal map to use.</param>
        /// <param name="magnitude">Magnitude to multiply by during calculation.</param>
        public FleeMap(GoalMap baseMap, double magnitude = 1.2)
        {
            _baseMap   = baseMap ?? throw new ArgumentNullException(nameof(baseMap));
            Magnitude  = magnitude;
            _goalMap   = new ArrayView <double?>(baseMap.Width, baseMap.Height);
            _nodes     = new ArrayView <PositionNode>(baseMap.Width, baseMap.Height);
            _openSet   = new GenericPriorityQueue <PositionNode, double>(baseMap.Width * baseMap.Height);
            _edgeSet   = new Queue <Point>();
            _closedSet = new BitArray(baseMap.Width * baseMap.Height);
            foreach (var pos in _nodes.Positions())
            {
                _nodes[pos] = new PositionNode(pos);
            }

            _baseMap.Updated += Update;

            // Necessary to ensure the FleeMap is valid immediately after construction
            Update();
        }