- getBasicMove([sx, sy], [ex, ey], tr) {
- if (
- tr &&
- Object.keys(V.HIDDEN_DECODE).includes(this.board[sx][sy].charAt(1))
- ) {
- // The transformed piece is a priori hidden
- tr.p = V.HIDDEN_CODE[tr.p];
- }
- let mv = new Move({
- appear: [
- new PiPo({
- x: ex,
- y: ey,
- c: tr ? tr.c : this.getColor(sx, sy),
- p: tr ? tr.p : this.board[sx][sy].charAt(1)
- })
- ],
- vanish: [
- new PiPo({
- x: sx,
- y: sy,
- c: this.getColor(sx, sy),
- p: this.board[sx][sy].charAt(1)
- })
- ]
- });
-
- // The opponent piece disappears if we take it
- if (this.board[ex][ey] != V.EMPTY) {
- mv.vanish.push(
- new PiPo({
- x: ex,
- y: ey,
- c: this.getColor(ex, ey),
- p: this.board[ex][ey].charAt(1)
- })
- );
- // Pieces are revealed when they capture
- mv.appear[0].p = V.Decode(mv.appear[0].p);
- }
-
- return mv;
- }
-
- // What are the king moves from square x,y ?
- getPotentialKingMoves(sq) {
- // No castling:
- return this.getSlideNJumpMoves(
- sq,
- V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
- "oneStep"
- );
- }
-
- filterValid(moves) {
- return moves;
- }
-
- static GenRandInitFen() {
- let pieces = { w: new Array(8), b: new Array(8) };
- // Shuffle pieces + pawns on two first ranks
- for (let c of ["w", "b"]) {
- let positions = ArrayFun.range(16);
-
- // Get random squares for bishops
- let randIndex = 2 * randInt(8);
- const bishop1Pos = positions[randIndex];
- // The second bishop must be on a square of different color
- let randIndex_tmp = 2 * randInt(8) + 1;
- const bishop2Pos = positions[randIndex_tmp];
- // Remove chosen squares
- positions.splice(Math.max(randIndex, randIndex_tmp), 1);
- positions.splice(Math.min(randIndex, randIndex_tmp), 1);
-
- // Get random squares for knights
- randIndex = randInt(14);
- const knight1Pos = positions[randIndex];
- positions.splice(randIndex, 1);
- randIndex = randInt(13);
- const knight2Pos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- // Get random squares for rooks
- randIndex = randInt(12);
- const rook1Pos = positions[randIndex];
- positions.splice(randIndex, 1);
- randIndex = randInt(11);
- const rook2Pos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- // Get random square for queen
- randIndex = randInt(10);
- const queenPos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- // Get random square for king
- randIndex = randInt(9);
- const kingPos = positions[randIndex];
- positions.splice(randIndex, 1);
-
- // Pawns position are all remaining slots:
- for (let p of positions)
- pieces[c][p] = "s";
-
- // Finally put the shuffled pieces in the board array
- pieces[c][rook1Pos] = "u";
- pieces[c][knight1Pos] = "o";
- pieces[c][bishop1Pos] = "c";
- pieces[c][queenPos] = "t";
- pieces[c][kingPos] = "l";
- pieces[c][bishop2Pos] = "c";
- pieces[c][knight2Pos] = "o";
- pieces[c][rook2Pos] = "u";
- }
- let upFen = pieces["b"].join("");
- upFen = upFen.substr(0,8) + "/" + upFen.substr(8).split("").reverse().join("");
- let downFen = pieces["b"].join("").toUpperCase();
- downFen = downFen.substr(0,8) + "/" + downFen.substr(8).split("").reverse().join("");
- return upFen + "/8/8/8/8/" + downFen + " w 0";
- }
-
- getCheckSquares() {
- return [];
- }