Yep
This commit is contained in:
@@ -1,19 +1,32 @@
|
||||
using System.Diagnostics;
|
||||
using static Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing.Path;
|
||||
|
||||
namespace Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
|
||||
[DebuggerDisplay("{Direction} - {Distance}")]
|
||||
[DebuggerDisplay("{Step} - {Distance}")]
|
||||
public record Path
|
||||
{
|
||||
public Vector2 NormalizedDirection { get; }
|
||||
public Vector2 Step { get; }
|
||||
public Vector2 NormalizedStep => Vector2.Normalize(Step);
|
||||
public Distance Distance { get; }
|
||||
|
||||
public Path(Vector2 direction, Distance distance = Distance.OneStep)
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="step">The smallest distance that can occur during a move.</param>
|
||||
/// <param name="distance"></param>
|
||||
public Path(Vector2 step, Distance distance = Distance.OneStep)
|
||||
{
|
||||
NormalizedDirection = Vector2.Normalize(direction);
|
||||
Step = step;
|
||||
this.Distance = distance;
|
||||
}
|
||||
public Path Invert() => new(Vector2.Negate(NormalizedDirection), Distance);
|
||||
public Path Invert() => new(Vector2.Negate(Step), Distance);
|
||||
|
||||
//public enum PathingResult
|
||||
//{
|
||||
// Obstructed,
|
||||
// CompletedWithoutObstruction
|
||||
//}
|
||||
}
|
||||
|
||||
public static class PathExtensions
|
||||
@@ -28,8 +41,8 @@ public static class PathExtensions
|
||||
var shortestPath = paths.First();
|
||||
foreach (var path in paths.Skip(1))
|
||||
{
|
||||
var distance = Vector2.Distance(start + path.NormalizedDirection, end); //Normalizing the direction probably broke this.
|
||||
var shortestDistance = Vector2.Distance(start + shortestPath.NormalizedDirection, end); // And this.
|
||||
var distance = Vector2.Distance(start + path.Step, end);
|
||||
var shortestDistance = Vector2.Distance(start + shortestPath.Step, end);
|
||||
if (distance < shortestDistance)
|
||||
{
|
||||
shortestPath = path;
|
||||
|
||||
Reference in New Issue
Block a user