private void InsertNewPiece(Piece piece, ChessPosition chessPosition) { ChessBoard.PutPiece(piece, chessPosition.ToPosition()); OutOfGamePieces.Remove(piece); InGamePieces.Add(piece); }
private void RemovePiece(ChessPosition chessPosition, Piece piece) { RemovePiece(chessPosition); InGamePieces.Remove(piece); OutOfGamePieces.Add(piece); }
private void UndoMovement(ChessPosition origin, ChessPosition target, Piece removedPiece) { var oldOriginPiece = ChessBoard.GetPiece(target.ToPosition()); RemovePiece(target); InsertPiece(oldOriginPiece, origin); oldOriginPiece.DecrementMovement(); if (removedPiece != null) { InsertNewPiece(removedPiece, target); } }
public void ExecuteMovement(ChessPosition origin, ChessPosition target) { var originPiece = ChessBoard.GetPiece(origin.ToPosition()); if (originPiece.IsPossibleMovement(target.ToPosition())) { RemovePiece(origin); var currentTargetPiece = ChessBoard.GetPiece(target.ToPosition()); if (currentTargetPiece != null) { RemovePiece(target, currentTargetPiece); } InsertPiece(originPiece, target); // Verify if the player CHECKED himself or if the player already is on CHECK if (IsInCheck(GetKing(CurrentPlayer))) { UndoMovement(origin, target, currentTargetPiece); if (Check) { throw new ChessMatchException("You are on CHECK!"); } else { throw new ChessMatchException("You can't CHECK yourself"); } } // Verify if the player CHECKED the adversary Check = IsInCheck(GetKing(Adversary(CurrentPlayer))); // Verify if the player CHECKMATE the adversary if (Check) { if (IsInCheckMate(GetKing(Adversary(CurrentPlayer)))) { Finished = true; FinishedAt = DateTime.Now; } } NextTurn(originPiece); } else { throw new ChessMatchException("This piece can't make this movement"); } }
public void CheckOriginPosition(ChessPosition origin) { if (ChessBoard.PieceExists(origin.ToPosition())) { if (!ChessBoard.GetPiece(origin.ToPosition()).Color.Equals(CurrentPlayer)) { throw new ChessMatchException("You can only movement your pieces"); } } else { throw new ChessBoardException("Not exist a piece in this position"); } }
private void RemovePiece(ChessPosition chessPosition) { ChessBoard.RemovePiece(chessPosition.ToPosition()); }
private void InsertPiece(Piece piece, ChessPosition chessPosition) { ChessBoard.PutPiece(piece, chessPosition.ToPosition()); }
public void CheckTargetPosition(ChessPosition target) { ChessBoard.ValidPosition(target.ToPosition()); }