Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 13x 13x 13x 13x 13x 13x 13x 13x 2753x 2753x 464x 464x 464x 464x 464x 464x 2753x 1379x 1379x 1379x 1379x 1379x 1791x 1791x 1379x 1518x 1390x 1390x 1390x 1390x 1390x 1390x 1518x 178x 1379x 2753x 2753x 2753x 2753x 2753x 2753x 2753x | import { createPieceMoveRule } from "./pieceMoveRule.js"; function createStraightLineMoveRule(motionCoordinates) { let moveRule = createPieceMoveRule(); function getPossibleMovements () { let possibleMovements = []; for (let i=0; i < motionCoordinates.length; i++) possibleMovements.push(...getMovements(motionCoordinates[i])); return possibleMovements; } function getMovements(direction) { let movements = []; let origin = moveRule.getCurrentCoordinate(); let nextSquare = origin.getNextCoordinate(direction); let possible = moveRule.isEmptyCoordinate(nextSquare) || moveRule.isOpposingColor(nextSquare); while(possible && origin.getPosition() != nextSquare.getPosition() && !movements.map(mv=>mv.getPosition()).includes(nextSquare.getPosition())) { movements.push(nextSquare); if (moveRule.isOpposingColor(nextSquare)) return movements; nextSquare = nextSquare.getNextCoordinate(direction); possible = moveRule.isEmptyCoordinate(nextSquare) || moveRule.isOpposingColor(nextSquare); } return movements; } return { ...moveRule, ...{ getPossibleMovements, } } } export { createStraightLineMoveRule } |