yep
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
namespace Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing
|
||||
namespace Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
|
||||
public enum Distance
|
||||
{
|
||||
public enum Distance
|
||||
{
|
||||
OneStep,
|
||||
MultiStep
|
||||
}
|
||||
/// <summary>
|
||||
/// Signifies that a piece can move one tile/position per move.
|
||||
/// </summary>
|
||||
OneStep,
|
||||
/// <summary>
|
||||
/// Signifies that a piece can move multiple tiles/positions in a single move.
|
||||
/// </summary>
|
||||
MultiStep
|
||||
}
|
||||
@@ -3,10 +3,17 @@
|
||||
namespace Shogi.Domain.YetToBeAssimilatedIntoDDD.Pathing;
|
||||
|
||||
[DebuggerDisplay("{Direction} - {Distance}")]
|
||||
public record Path(Vector2 Direction, Distance Distance = Distance.OneStep)
|
||||
public record Path
|
||||
{
|
||||
public Vector2 NormalizedDirection { get; }
|
||||
public Distance Distance { get; }
|
||||
|
||||
public Path Invert() => new(Vector2.Negate(Direction), Distance);
|
||||
public Path(Vector2 direction, Distance distance = Distance.OneStep)
|
||||
{
|
||||
NormalizedDirection = Vector2.Normalize(direction);
|
||||
this.Distance = distance;
|
||||
}
|
||||
public Path Invert() => new(Vector2.Negate(NormalizedDirection), Distance);
|
||||
}
|
||||
|
||||
public static class PathExtensions
|
||||
@@ -21,8 +28,8 @@ public static class PathExtensions
|
||||
var shortestPath = paths.First();
|
||||
foreach (var path in paths.Skip(1))
|
||||
{
|
||||
var distance = Vector2.Distance(start + path.Direction, end);
|
||||
var shortestDistance = Vector2.Distance(start + shortestPath.Direction, end);
|
||||
var distance = Vector2.Distance(start + path.NormalizedDirection, end); //Normalizing the direction probably broke this.
|
||||
var shortestDistance = Vector2.Distance(start + shortestPath.NormalizedDirection, end); // And this.
|
||||
if (distance < shortestDistance)
|
||||
{
|
||||
shortestPath = path;
|
||||
|
||||
Reference in New Issue
Block a user