Better fix
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user