/// <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 ArrayMap <double?>(baseMap.Width, baseMap.Height); _nodes = new ArrayMap <PositionNode>(baseMap.Width, baseMap.Height); foreach (var pos in _nodes.Positions()) { _nodes[pos] = new PositionNode(pos); } _baseMap.Updated += Update; }
/// <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(); }