This commit is contained in:
2021-03-03 07:33:12 -06:00
parent 2e976c01e9
commit e64f75e3cc
7 changed files with 90 additions and 12 deletions

View File

@@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>
<ItemGroup>

View File

@@ -16,7 +16,7 @@ namespace Gameboard.ShogiUI.BoardState
{
private delegate void MoveSetCallback(Piece piece, Vector2 position);
private readonly PathFinder2D<Piece> pathFinder;
public ShogiBoard validationBoard;
private ShogiBoard validationBoard;
private Vector2 player1King;
private Vector2 player2King;
public IReadOnlyDictionary<WhichPlayer, List<Piece>> Hands { get; }
@@ -46,6 +46,7 @@ namespace Gameboard.ShogiUI.BoardState
{
if (!Move(moves[i]))
{
// Todo: Add some smarts to know why a move was invalid. In check? Piece not found? etc.
throw new InvalidOperationException($"Unable to construct ShogiBoard with the given move at index {i}.");
}
}
@@ -135,16 +136,16 @@ namespace Gameboard.ShogiUI.BoardState
{
case WhichPiece.Knight:
// Knight cannot be placed onto the farthest two ranks from the hand.
minimumY = WhoseTurn == WhichPlayer.Player1 ? 2 : 6;
minimumY = WhoseTurn == WhichPlayer.Player1 ? 6 : 2;
break;
case WhichPiece.Lance:
case WhichPiece.Pawn:
// Lance and Pawn cannot be placed onto the farthest rank from the hand.
minimumY = WhoseTurn == WhichPlayer.Player1 ? 1 : 7;
minimumY = WhoseTurn == WhichPlayer.Player1 ? 7 : 1;
break;
}
if (WhoseTurn == WhichPlayer.Player1 && move.To.Y < minimumY) return false;
if (WhoseTurn == WhichPlayer.Player2 && move.To.Y > minimumY) return false;
if (WhoseTurn == WhichPlayer.Player1 && move.To.Y > minimumY) return false;
if (WhoseTurn == WhichPlayer.Player2 && move.To.Y < minimumY) return false;
// Mutate the board.
Board[move.To.X, move.To.Y] = Hands[WhoseTurn][index];