Better fix

This commit is contained in:
2024-11-01 21:38:33 -05:00
parent d8432b98fe
commit 7258ac29a0
3 changed files with 47 additions and 28 deletions

View File

@@ -330,23 +330,35 @@ public sealed class ShogiBoard(BoardState initialState)
var clampedFromTo = Vector2.Clamp(to - from, -Vector2.One, Vector2.One);
var matchingPaths = piece.MoveSet.Where(p => p.Step == clampedFromTo);
if (!matchingPaths.Any())
if (Vector2.Distance(to, from) < 2)
{
return new MoveResult(false, "Piece cannot move like that.");
}
var multiStepPaths = matchingPaths.Where(path => path.Distance == YetToBeAssimilatedIntoDDD.Pathing.Distance.MultiStep).ToArray();
foreach (var path in multiStepPaths)
{
// Assert that no pieces exist along the from -> to path.
var isPathObstructed = GetPositionsAlongPath(from, to, path)
.SkipLast(1)
.Any(pos => BoardState[pos] != null);
if (isPathObstructed)
if (!matchingPaths.Any())
{
return new MoveResult(false, "Piece cannot move through other pieces.");
return new MoveResult(false, "Piece cannot move like that.");
}
}
else
{
var multiStepPaths = matchingPaths
.Where(path => path.Distance == YetToBeAssimilatedIntoDDD.Pathing.Distance.MultiStep)
.ToArray();
if (multiStepPaths.Length == 0)
{
return new MoveResult(false, "Piece cannot move like that");
}
foreach (var path in multiStepPaths)
{
// Assert that no pieces exist along the from -> to path.
var isPathObstructed = GetPositionsAlongPath(from, to, path)
.SkipLast(1)
.Any(pos => BoardState[pos] != null);
if (isPathObstructed)
{
return new MoveResult(false, "Piece cannot move through other pieces.");
}
}
}
var pieceAtTo = BoardState[to];