All files / moveRule queenMoveRule.js

100% Statements 28/28
100% Branches 4/4
100% Functions 3/3
100% Lines 28/28

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 2913x 13x 13x 13x 13x 13x 13x 13x 13x 13x 791x 791x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x 60x  
import { createPieceMoveRule } from "./pieceMoveRule.js";
import { getRookMoveRule } from "./rookMoveRule.js";
import { getBishopMoveRule } from "./bishopMoveRule.js";
 
function getQueenMoveRule() {
    let moveRule = createPieceMoveRule();
    let straightMovement = getRookMoveRule();
    let diagonalMovement = getBishopMoveRule();
 
    function getPossibleMovements () {
        straightMovement.updateCurrentPosition(moveRule.getCurrentCoordinate().getPosition(), moveRule.getBoardPieces());
        diagonalMovement.updateCurrentPosition(moveRule.getCurrentCoordinate().getPosition(), moveRule.getBoardPieces());
        let movements = straightMovement.getPossibleMovements();
        movements.push(...diagonalMovement.getPossibleMovements());
        return movements;
    }
 
    return {
        ...moveRule,
        ...{
            getPossibleMovements,
        }
    }
}
 
export {
    getQueenMoveRule
}