All files / main boardBuilder.js

100% Statements 40/40
100% Branches 6/6
100% Functions 5/5
100% Lines 40/40

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 4110x 10x 10x 10x 10x 10x 10x 10x 897x 897x 897x 897x 897x 897x 897x 897x 897x 897x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 897x 897x 897x 897x  
import { createBoard } from './board.js';
import { piecesBuilder } from '../piece/piecesBuilder.js';
 
function boardBuilder() {
    let board = createBoard();
 
    function fromPieceLayoutString(pieceStringLayout) {
        pieceStringLayout = pieceStringLayout.trim().split('\n').join('-').split('-');
        board.setPieces(piecesBuilder(pieceStringLayout).buildFromLayout());
        return this;
    }
 
    function usingInitialPieceDisposition() {
        fromPieceLayoutString(`
            BR-BH-BB-BK-BQ-BB-BH-BR
            BP-BP-BP-BP-BP-BP-BP-BP
            _-_-_-_-_-_-_-_
            _-_-_-_-_-_-_-_
            _-_-_-_-_-_-_-_
            _-_-_-_-_-_-_-_
            WP-WP-WP-WP-WP-WP-WP-WP
            WR-WH-WB-WK-WQ-WB-WH-WR
        `);
        return this;
    }
 
    function build() {
        return board;
    }
 
    return {
        fromPieceLayoutString,
        usingInitialPieceDisposition,
        build
    }
}
 
export {
    boardBuilder
}