Files
prosperon/examples/chess/pieces.cm
2026-01-21 09:05:02 -06:00

29 lines
710 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* pieces.js simple data holders + starting layout */
function Piece(kind, colour) {
var newpiece = { kind, colour}
newpiece.sprite = colour + '_' + kind; // for draw2d.image
newpiece.captured = false;
newpiece.coord = [0,0];
return newpiece
}
function startingPosition(grid) {
var W = 'white', B = 'black', x;
// pawns
for (x = 0; x < 8; x++) {
grid.add(Piece('pawn', W), [x, 6]);
grid.add(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(Piece(back[x], W), [x, 7]);
grid.add(Piece(back[x], B), [x, 0]);
}
}
return { Piece, startingPosition };