public bool IsMoveLegal(BoardCoordinate origin, BoardCoordinate destination) { var isCapture = destination.IsCoordinateValidForBoardSize(_boardSize) && GetPiece(destination) != null; var isIllegalCapture = isCapture && !GetPiece(origin).IsCaptureAllowed(origin, destination); var isIllegalNonCapture = !isCapture && !GetPiece(origin).IsNonCaptureAllowed(origin, destination); return(!isIllegalCapture && !isIllegalNonCapture && destination.IsCoordinateValidForBoardSize(_boardSize) && !IsBlocked(origin, destination) && !DoesFriendlyPieceExistAt(origin, destination)); }
public void AddPiece(Piece piece, BoardCoordinate moveTarget) { if (piece == null) throw new ArgumentNullException("piece"); if (!moveTarget.IsCoordinateValidForBoardSize(_boardSize)) throw new ArgumentException("moveTarget"); SetPiece(piece, moveTarget); }
private void SetEnPassantIfPawnExistsAtTarget(BoardCoordinate destination, BoardCoordinate enPassantTarget) { if (enPassantTarget.IsCoordinateValidForBoardSize(_boardSize)) { var targetPawn = GetPiece(enPassantTarget) as Pawn; if (targetPawn != null) { targetPawn.SetCanPerformEnPassantOn(destination); } } }
public void AddPiece(Piece piece, BoardCoordinate moveTarget) { if (piece == null) { throw new ArgumentNullException("piece"); } if (!moveTarget.IsCoordinateValidForBoardSize(_boardSize)) { throw new ArgumentException("moveTarget"); } SetPiece(piece, moveTarget); }
private bool IsMoveLegal(BoardCoordinate origin, BoardCoordinate destination) { var isCapture = destination.IsCoordinateValidForBoardSize(_boardSize) && GetPiece(destination) != null; var isIllegalCapture = isCapture && !GetPiece(origin).IsCaptureAllowed(origin, destination); var isIllegalNonCapture = !isCapture && !GetPiece(origin).IsNonCaptureAllowed(origin, destination); return !isIllegalCapture && !isIllegalNonCapture && destination.IsCoordinateValidForBoardSize(_boardSize) && !IsBlocked(origin, destination) && !DoesFriendlyPieceExistAt(origin, destination); }
private void SetEnPassantIfPawnExistsAtTarget(BoardCoordinate destination, BoardCoordinate enPassantTarget) { if (enPassantTarget.IsCoordinateValidForBoardSize(_boardSize)) { var targetPawn = GetPiece(enPassantTarget) as Pawn; if (targetPawn != null) targetPawn.SetCanPerformEnPassantOn(destination); } }
public void Returns_False_For_Y_Less_Than_Zero() { var coordinate = new BoardCoordinate(1, -23); Assert.IsFalse(coordinate.IsCoordinateValidForBoardSize(8)); }
public void Returns_False_For_X_Less_Than_Zero() { var coordinate = new BoardCoordinate(-12, 2); Assert.IsFalse(coordinate.IsCoordinateValidForBoardSize(5)); }