'n': 'w',
'b': 'f',
'q': 'c',
- 'k': 'k',
- 'p': 'p'
+ 'k': 'm',
+ 'p': 'z'
},
// Nutty Knights
'N': {
'n': 'i',
'b': 't',
'q': 'l',
- 'k': 'k', //TODO: e
- 'p': 'p' //TODO: v
+ 'k': 'e',
+ 'p': 'v'
},
// Remarkable Rookies
'R': {
this.army2 = armies.charAt(1);
}
+ scanKings(fen) {
+ this.kingPos = { w: [-1, -1], b: [-1, -1] };
+ const fenRows = V.ParseFen(fen).position.split("/");
+ for (let i = 0; i < fenRows.length; i++) {
+ let k = 0;
+ for (let j = 0; j < fenRows[i].length; j++) {
+ const newChar = fenRows[i].charAt(j);
+ if (['a', 'e', 'k', 'm'].includes(newChar))
+ this.kingPos["b"] = [i, k];
+ else if (['A', 'E', 'K', 'M'].includes(newChar))
+ this.kingPos["w"] = [i, k];
+ else {
+ const num = parseInt(fenRows[i].charAt(j), 10);
+ if (!isNaN(num)) k += num - 1;
+ }
+ k++;
+ }
+ }
+ }
+
static ParseFen(fen) {
return Object.assign(
{ armies: fen.split(" ")[5] },
static get C_QUEEN() {
return 'c';
}
+ static get C_KING() {
+ return 'm';
+ }
+ static get C_PAWN() {
+ return 'z';
+ }
static get N_ROOK() {
return 'g';
}
getPiece(x, y) {
const p = this.board[x][y][1];
- if (['u', 'v'].includes(p)) return 'p';
- if (['a', 'e'].includes(p)) return 'k';
+ if (['u', 'v', 'z'].includes(p)) return 'p';
+ if (['a', 'e', 'm'].includes(p)) return 'k';
return p;
}
static get PIECES() {
return ChessRules.PIECES.concat(
[
- V.C_ROOK, V.C_KNIGHT, V.C_BISHOP, V.C_QUEEN,
+ V.C_ROOK, V.C_KNIGHT, V.C_BISHOP, V.C_QUEEN, V.C_KING, V.C_PAWN,
V.N_ROOK, V.N_KNIGHT, V.N_BISHOP, V.N_QUEEN, V.N_KING, V.N_PAWN,
V.R_ROOK, V.R_KNIGHT, V.R_BISHOP, V.R_QUEEN, V.R_KING, V.R_PAWN
]
);
}
+ getEpSquare(moveOrSquare) {
+ if (!moveOrSquare) return undefined; //TODO: necessary line?!
+ if (typeof moveOrSquare === "string") {
+ const square = moveOrSquare;
+ if (square == "-") return undefined;
+ return V.SquareToCoords(square);
+ }
+ // Argument is a move:
+ const move = moveOrSquare;
+ const s = move.start,
+ e = move.end;
+ if (
+ s.y == e.y &&
+ Math.abs(s.x - e.x) == 2 &&
+ ['p', 'u', 'v'].includes(move.appear[0].p)
+ ) {
+ return {
+ x: (s.x + e.x) / 2,
+ y: s.y
+ };
+ }
+ return undefined; //default
+ }
+
getPotentialMovesFrom(sq) {
switch (this.getPiece(sq[0], sq[1])) {
case V.C_ROOK: return this.getPotentialC_rookMoves(sq);
return super.isAttackedByQueen(sq, color);
}
+ postPlay(move) {
+ const c = V.GetOppCol(this.turn);
+ const piece = move.appear[0].p;
+ // Update king position + flags
+ if (['k', 'a', 'e', 'm'].includes(piece)) {
+ this.kingPos[c][0] = move.appear[0].x;
+ this.kingPos[c][1] = move.appear[0].y;
+ this.castleFlags[c] = [V.size.y, V.size.y];
+ }
+ // Next call is still required because the king may eat an opponent's rook
+ // TODO: castleFlags will be turned off twice then.
+ super.updateCastleFlags(move, piece);
+ }
+
+ postUndo(move) {
+ // (Potentially) Reset king position
+ const c = this.getColor(move.start.x, move.start.y);
+ const piece = move.appear[0].p;
+ if (['k', 'a', 'e', 'm'].includes(piece))
+ this.kingPos[c] = [move.start.x, move.start.y];
+ }
+
static get VALUES() {
return Object.assign(
{
return 2;
}
+ getNotation(move) {
+ let notation = super.getNotation(move);
+ if (['u', 'v', 'z'].includes(move.appear[0].p))
+ notation = notation.slice(0, -2);
+ return notation;
+ }
+
};