我正在思考一种高效且整洁的方法来确定在国际象棋中使用主教进行有效移动。
该棋子将从srcX、srcY移动到dstX、dstY。
以下是我的其中一个想法的一部分:
if(srcX < dstX && srcY < dstY) {
// Moving towards the top right of the board
// Determine the decrease in X coordinate
int deltaX = dstX-srcX;
// If the move is valid, the Y coordinate will have decreased by the same number as X
int validY = dstY-deltaX;
if(validY == srcY) {
validMove = true;
}
}
但是这样做每个角落都要花费很长时间,有没有更好的方法?
涉及IT技术。
srcx - dstx
和srcy - dsty
的绝对值吗? - Maxpm