All files piece.js

100% Statements 24/24
100% Branches 0/0
100% Functions 13/13
100% Lines 24/24

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115                            9x                 9x             5457x 5457x 5457x 5457x       681x       340x       682x       2729x       342x       683x           681x   681x           340x   340x           682x   682x           2729x   2729x           342x   342x           683x   683x                  
/**
	The Piece is a definition of a piece that can be played on the board.
 
	The uid property of the Piece is not intended to be durable across
	sessions, but only to uniquely identify the piece on the board. Right
	now the property is used by board.getSquareByPiece as pieces are not
	otherwise uniquely identifiable (i.e. getSquareByPiece(Pawn) would
	return the first square found with a Pawn on it rather than the exact
	square intended). Additionally, the uid of the Piece is used in
	BoardValidation to ensure there is correllation between the piece and
	valid squares to which the piece can move.
*/
 
// types
export var PieceType = {
	Bishop : 'bishop',
	King : 'king',
	Knight : 'knight',
	Pawn : 'pawn',
	Queen : 'queen',
	Rook : 'rook'
};
 
export var SideType = {
	Black : { name : 'black' },
	White : { name : 'white' }
};
 
export class Piece {
	constructor (side, notation) {
		this.moveCount = 0;
		this.notation = notation;
		this.side = side;
		this.type = null;
	}
 
	static createBishop (side) {
		return new Bishop(side);
	}
 
	static createKing (side) {
		return new King(side);
	}
 
	static createKnight (side) {
		return new Knight(side);
	}
 
	static createPawn (side) {
		return new Pawn(side);
	}
 
	static createQueen (side) {
		return new Queen(side);
	}
 
	static createRook (side) {
		return new Rook(side);
	}
}
 
export class Bishop extends Piece {
	constructor (side) {
		super(side, 'B');
 
		this.type = PieceType.Bishop;
	}
}
 
export class King extends Piece {
	constructor (side) {
		super(side, 'K');
 
		this.type = PieceType.King;
	}
}
 
export class Knight extends Piece {
	constructor (side) {
		super(side, 'N');
 
		this.type = PieceType.Knight;
	}
}
 
export class Pawn extends Piece {
	constructor (side) {
		super(side, '');
 
		this.type = PieceType.Pawn;
	}
}
 
export class Queen extends Piece {
	constructor (side) {
		super(side, 'Q');
 
		this.type = PieceType.Queen;
	}
}
 
export class Rook extends Piece {
	constructor (side) {
		super(side, 'R');
 
		this.type = PieceType.Rook;
	}
}
 
export default {
	Piece,
	PieceType,
	SideType
};