- getColor(i, j) {
- if (i >= V.size.x) return i == V.size.x ? "w" : "b";
- return this.board[i][j].charAt(0);
- }
-
- getPiece(i, j) {
- if (i >= V.size.x) return V.RESERVE_PIECES[j];
- return this.board[i][j].charAt(1);
- }
-
- getPpath(b) {
- return (V.NON_VIOLENT.includes(b[1]) ? "Clorange/" : "") + b;
- }
-
- getReservePpath(index, color) {
- const prefix =
- (V.NON_VIOLENT.includes(V.RESERVE_PIECES[index]) ? "Clorange/" : "");
- return prefix + color + V.RESERVE_PIECES[index];
- }
-
- static get NON_VIOLENT() {
- return ['s', 'u', 'o', 'c', 't'];
- }
-
- static get PIECES() {
- return ChessRules.PIECES.concat(V.NON_VIOLENT);
- }
-
- // Ordering on reserve pieces
- static get RESERVE_PIECES() {
- return V.PIECES.filter(p => p != 'k');
- }
-
- getReserveMoves([x, y]) {
- const color = this.turn;
- const p = V.RESERVE_PIECES[y];
- if (this.reserve[color][p] == 0) return [];
- let moves = [];
- let rank1 = 0;
- let rank2 = V.size.x - 1;
- if (['p', 's'].includes(p)) {
- if (color == 'w') rank1++;
- else rank2--;
- }
- for (let i = rank1; i <= rank2; i++) {
- for (let j = 0; j < V.size.y; j++) {
- if (this.board[i][j] == V.EMPTY) {
- let mv = new Move({
- appear: [
- new PiPo({
- x: i,
- y: j,
- c: color,
- p: p
- })
- ],
- vanish: [],
- start: { x: x, y: y }, //a bit artificial...
- end: { x: i, y: j }
- });
- moves.push(mv);
- }
- }
- }
- return moves;
- }
-
- getPotentialMovesFrom([x, y]) {
- if (x >= V.size.x)
- // Reserves, outside of board: x == sizeX(+1)
- return this.getReserveMoves([x, y]);
- // Standard moves
- switch (this.getPiece(x, y)) {
- case 's': return this.getPotentialPawnMoves([x, y]);
- case 'u': return super.getPotentialRookMoves([x, y]);
- case 'o': return super.getPotentialKnightMoves([x, y]);
- case 'c': return super.getPotentialBishopMoves([x, y]);
- case 't': return super.getPotentialQueenMoves([x, y]);
- default: return super.getPotentialMovesFrom([x, y]);
- }
- return []; //never reached
- }
-
- getPotentialPawnMoves(sq) {
- let moves = super.getPotentialPawnMoves(sq);
- if (moves.length > 0 && moves[0].vanish[0].p == 's') {
- // Remove captures for non-violent pawns:
- moves = moves.filter(m => m.vanish.length == 1);
- moves.forEach(m => {
- if (m.appear[0].p != 's') {
- // Promotion pieces should be non-violent as well:
- const pIdx = ChessRules.PIECES.findIndex(p => p == m.appear[0].p)
- m.appear[0].p = V.NON_VIOLENT[pIdx];
- }
- });
- }
- return moves;