На изображении вы можете увидеть шоу Найта на C3, но его фактическая позиция - A4. Аналогичное поведение слона и ладьи.
for(let j = 1; j < 8; j++) {
Код: Выделить всё
if(piecePosition.row+j < 8 && piecePosition.col+j < 8) {
position = {
row: piecePosition.row+j,
col: piecePosition.col+j
}
let clr = getColorOfPieceAtPosition(position, activeBoard);
if(clr != playerColor) {
if(chessCheck) {
// with this move player would still be in chess position or set self in chess
if(makeMoveAndCheckIfChess(piecePosition, position, playerColor)) {
// if there's a collision at new position end here
if(clr) {
break;
// if there's no coliision next move could still be valid
} else {
continue;
}
}
}
legalMoves.push(position);
if(clr) {
break;
}
} else {
break;
}
} else {
// out of bounds
break;
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... e-user-end
Мобильная версия