Search code examples
algorithmvalidationchess

Chess Bishop movement pattern validation


I understand that abs(srcX-dstX) == abs(srcY-dstY) is a correct validation for the movement pattern of the bishop piece.

But I would like to know if my validation is also correct, here it is:
srcX-srcY == dstX-dstY || srcX+srcY == dstX+dstY

If your answer is no, please specify why.


Solution

  • Yes its correct. The basic method is to take original equation and remove the absolute value and then do the same but multiply by -1 on one side so

    Given: abs(srcX-dstX) == abs(srcY-dstY)
    srcX-dstX == srcY-dstY OR srcX-dstX == -srcY+dstY
    

    This can be rearranged to look like yours.