шахматы, ход слоном

Есть код хода слоном. Вообще задача стояла так чтобы оказать сможет ли слон достичь какой либо клетки за определённое количество шагов или нет, но у меня не приняли, сказав, чо по сути у меня в коде слон ходит по 1 клетку по диагонали и до какой либо точки он может за 1 шаг добраться

    const mountinElephant = (coord, a, b) => Array(8).fill(Array(8).fill(null)).map((row, idx) => {
  if (coord.row !== idx) {
    const arr = row.map((col, i) => i === a | i === b ? 'o' : col);
    a++; b--;
    return arr
  } else {
    const arr = row.map((col, i) => coord.col !== i ? col : 'e');
    a++; b--;
    return arr;
  }
});    // e = your figure of elephant; o = access Cells for the elephant
 
const accessCells = (coord) => {
  let {col: kBack, col: kForward} = coord;    
  for (let r = coord.row; r !== 0; r--, kBack--, kForward++);
  const tmpArray = mountinElephant(coord, kBack, kForward);
  return tmpArray;
}
 
function moveElephant(n, curPos, newPos) {
  const chessBoard = accessCells(curPos);  // Here we default mounting position for elephant (value from 0 to 7)
 
  if (/[0-7]/.test(n) && /[0-7]/.test(newPos.row) && /[0-7]/.test(newPos.col) && /[0-7]/.test(curPos.col) && /[0-7]/.test(curPos.row)) {
    const curRow = curPos.row > newPos.row ? curPos.row - numberOfSteps : curPos.row + numberOfSteps;
    const curCol = curPos.col > newPos.col ? curPos.col - numberOfSteps : curPos.col + numberOfSteps;
 
    if (curRow === newPos.row && curCol === newPos.col) {
      const tmpArray = chessBoard.map((row, idx) => curRow === idx ? row.map((col, i) => i === curCol ? 'E' : col) : row);
      return {board: tmpArray, value: true};
    } else {
      return {board: chessBoard, value: false};
    }
  } else {
    console.error(`Input correct value (value "n" and "newPos" must be from 0 to 7). Example: moveElephant(4, {row: 7, col: 0})`);
    return {board: chessBoard, value: false};
  }
}
 
const numberOfSteps = 3;<--- количество ходов
const currentPosition = {row: 4, col: 5};<---начальная позиция
const newPosition = {row: 7, col: 2};<---конечная позиция
 
const result = moveElephant(numberOfSteps, currentPosition, newPosition);
 
console.log(result.value);  // false or true
console.log(result.board);  // update chess board

Ответы (0 шт):