Fixed accidentally building the board from player2 perspective.

This commit is contained in:
2021-04-06 19:52:02 -05:00
parent 2d5c6b20b9
commit 05a9c71499
45 changed files with 441 additions and 276 deletions

View File

@@ -4,15 +4,15 @@ namespace PathFinding
{
public static class Direction
{
public static readonly Vector2 Up = new(0, 1);
public static readonly Vector2 Down = new(0, -1);
public static readonly Vector2 Up = new(0, -1);
public static readonly Vector2 Down = new(0, 1);
public static readonly Vector2 Left = new(-1, 0);
public static readonly Vector2 Right = new(1, 0);
public static readonly Vector2 UpLeft = new(-1, 1);
public static readonly Vector2 UpRight = new(1, 1);
public static readonly Vector2 DownLeft = new(-1, -1);
public static readonly Vector2 DownRight = new(1, -1);
public static readonly Vector2 KnightLeft = new(-1, 2);
public static readonly Vector2 KnightRight = new(1, 2);
public static readonly Vector2 UpLeft = new(-1, -1);
public static readonly Vector2 UpRight = new(1, -1);
public static readonly Vector2 DownLeft = new(-1, 1);
public static readonly Vector2 DownRight = new(1, 1);
public static readonly Vector2 KnightLeft = new(-1, -2);
public static readonly Vector2 KnightRight = new(1, -2);
}
}

View File

@@ -6,8 +6,6 @@ namespace PathFinding
{
public class PathFinder2D<T> where T : IPlanarElement
{
/// <summary>
/// </summary>
/// <param name="element">Guaranteed to be non-null.</param>
/// <param name="position"></param>
public delegate void Callback(T collider, Vector2 position);
@@ -108,14 +106,8 @@ namespace PathFinding
public static Move FindDirectionTowardsDestination(ICollection<Move> paths, Vector2 origin, Vector2 destination) =>
paths.Aggregate((a, b) => Vector2.Distance(destination, Vector2.Add(origin, a.Direction)) < Vector2.Distance(destination, Vector2.Add(origin, b.Direction)) ? a : b);
public static bool IsPathable(Vector2 origin, Vector2 destination, T element)
{
var path = FindDirectionTowardsDestination(element.MoveSet.GetMoves(), origin, destination);
return IsPathable(origin, destination, path.Direction);
}
public static bool IsPathable(Vector2 origin, Vector2 destination, Vector2 direction)
{
direction = Vector2.Normalize(direction);
var next = Vector2.Add(origin, direction);
if (Vector2.Distance(next, destination) >= Vector2.Distance(origin, destination)) return false;