This commit is contained in:
2022-06-07 21:22:12 -05:00
parent 3a9a627e0d
commit dabdb6c6b0
2 changed files with 34 additions and 16 deletions

View File

@@ -81,5 +81,15 @@ namespace Shogi.Domain.Pieces
return Array.Empty<Vector2>(); return Array.Empty<Vector2>();
} }
/// <summary>
/// Get all positions this piece could move to from the currentPosition, respecting the move-set of this piece.
/// </summary>
/// <param name="currentPosition"></param>
/// <returns>A list of positions the piece could move to.</returns>
public IEnumerable<Vector2> GetPossiblePositions(Vector2 currentPosition)
{
throw new NotImplementedException();
}
} }
} }

View File

@@ -1,4 +1,5 @@
using BoardTile = System.Collections.Generic.KeyValuePair<System.Numerics.Vector2, Shogi.Domain.Pieces.Piece>; using Shogi.Domain.Pathing;
using BoardTile = System.Collections.Generic.KeyValuePair<System.Numerics.Vector2, Shogi.Domain.Pieces.Piece>;
namespace Shogi.Domain namespace Shogi.Domain
{ {
@@ -206,27 +207,34 @@ namespace Shogi.Domain
.Where(tile => PieceHasLineOfSight(tile, threatBlockingPosition)) .Where(tile => PieceHasLineOfSight(tile, threatBlockingPosition))
.ToList(); .ToList();
if (tilesThatCouldBlockTheThreat.Any()) if (tilesThatDoBlockThreat.Any())
{ {
return false; // Cannot be check-mate if a piece can intercept the threat. return false; // Cannot be check-mate if a piece can intercept the threat.
} }
} }
//var line = Vector2.Subtract(kingPosition, threat.Position); }
//var slope = line.Y / line.X; else
//foreach (var tile in tilesThatCouldBlockTheThreat) {
//{ /*
// // y = mx + b; slope intercept * If no ability to block the check, maybe the king can evade check by moving.
// // b = -mx + y; */
// var b = -slope * tile.Position.X + tile.Position.Y;
// //if (tile.Position.Y = slope * tile.Position.X + )
//} // TODO: Implement this in the Piece class instead.
var possibleSafePositions = new[]
{
Direction.Up, Direction.Down, Direction.Left, Direction.Right, Direction.UpLeft, Direction.UpRight, Direction.DownLeft, Direction.DownRight
}
.Select(direction => kingPosition + direction);
foreach (var maybeSafePosition in possibleSafePositions)
{
} }
/* If no ability to block the check, maybe the king can evade check by moving. }
*
* Foreach position the king can reach
* Foreach piece owned by "other player", check if piece threatens king position.
*/
return false; return false;
} }