mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-09-29 17:41:06 +02:00
30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Microsoft.Xna.Framework;
|
|
using MLEM.Misc;
|
|
|
|
namespace MLEM.Pathfinding {
|
|
/// <summary>
|
|
/// A 2-dimensional implementation of <see cref="AStar{T}"/> that uses <see cref="Point"/> for positions.
|
|
/// </summary>
|
|
public class AStar2 : AStar<Point> {
|
|
|
|
private static readonly Point[] AdjacentDirs = Direction2Helper.Adjacent.Offsets().ToArray();
|
|
private static readonly Point[] AllDirs = Direction2Helper.All.Offsets().ToArray();
|
|
|
|
/// <inheritdoc />
|
|
public AStar2(GetCost defaultCostFunction, bool defaultAllowDiagonals, float defaultCost = 1, int defaultMaxTries = 10000) :
|
|
base(AStar2.AllDirs, AStar2.AdjacentDirs, defaultCostFunction, defaultAllowDiagonals, defaultCost, defaultMaxTries) {}
|
|
|
|
/// <inheritdoc />
|
|
protected override Point AddPositions(Point first, Point second) {
|
|
return first + second;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override float GetManhattanDistance(Point first, Point second) {
|
|
return Math.Abs(second.X - first.X) + Math.Abs(second.Y - first.Y);
|
|
}
|
|
|
|
}
|
|
}
|