Some checks failed
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-macos (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
30 lines
883 B
JavaScript
30 lines
883 B
JavaScript
/* 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 };
|