/* pieces.js – simple data holders + starting layout */ function Piece(kind, colour) { this.kind = kind; // "pawn" etc. this.colour = colour; // "white"/"black" this.sprite = colour + '_' + kind; // for draw2d.image this.captured = false; this.coord = [0,0]; } Piece.prototype.toString = function () { return this.colour.charAt(0) + this.kind.charAt(0).toUpperCase(); }; function startingPosition(grid) { var W = 'white', B = 'black', x; // pawns for (x = 0; x < 8; x++) { grid.add(new Piece('pawn', W), [x, 6]); grid.add(new Piece('pawn', B), [x, 1]); } // major pieces var back = ['rook','knight','bishop','queen','king','bishop','knight','rook']; for (x = 0; x < 8; x++) { grid.add(new Piece(back[x], W), [x, 7]); grid.add(new Piece(back[x], B), [x, 0]); } } return { Piece, startingPosition };