This commit is contained in:
2022-01-29 10:07:53 -06:00
parent 499e480851
commit f79a1312c7
4 changed files with 190 additions and 161 deletions

View File

@@ -43,16 +43,24 @@
public void Move(string from, string to, bool isPromotion)
{
var fromVector = ShogiBoardState.FromBoardNotation(from);
var toVector = ShogiBoardState.FromBoardNotation(to);
var moveResult = rules.Move(from, to, isPromotion);
var tempBoard = new ShogiBoardState(board);
var simulation = new StandardRules(tempBoard);
var moveResult = simulation.Move(from, to, isPromotion);
if (!moveResult.Success)
{
throw new InvalidOperationException(moveResult.Reason);
}
var fromVector = ShogiBoardState.FromBoardNotation(from);
var toVector = ShogiBoardState.FromBoardNotation(to);
var otherPlayer = board.WhoseTurn == WhichPlayer.Player1 ? WhichPlayer.Player2 : WhichPlayer.Player1;
if (rules.EvaluateCheckAfterMove(fromVector, toVector, otherPlayer))
if (simulation.IsPlayerInCheckAfterMove(fromVector, toVector, board.WhoseTurn))
{
throw new InvalidOperationException("Illegal move. This move places you in check.");
}
rules.Move(from, to, isPromotion);
if (rules.IsPlayerInCheckAfterMove(fromVector, toVector, otherPlayer))
{
board.InCheck = otherPlayer;
board.IsCheckmate = rules.EvaluateCheckmate();
@@ -64,6 +72,10 @@
board.WhoseTurn = otherPlayer;
}
public void Move(WhichPiece pieceInHand, string to)
{
}
///// <summary>
///// Attempts a given move. Returns false if the move is illegal.
///// </summary>