X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FMonochrome.js;h=8c74961bccff03af41f391dcc18455fb6c8175b5;hb=f9ecc49933b5f541724b73856ba816722ea26c34;hp=31cf59ea3deb066cd1bb13510c44a564733b999a;hpb=e50a802531b99829c533f22ecd21e359e7e1e049;p=vchess.git diff --git a/client/src/variants/Monochrome.js b/client/src/variants/Monochrome.js index 31cf59ea..8c74961b 100644 --- a/client/src/variants/Monochrome.js +++ b/client/src/variants/Monochrome.js @@ -6,6 +6,10 @@ export class MonochromeRules extends ChessRules { return false; } + static get HasFlags() { + return false; + } + static get Lines() { return [ [[4, 0], [4, 8]] ]; } @@ -45,7 +49,19 @@ export class MonochromeRules extends ChessRules { // Trim all non-capturing moves static KeepCaptures(moves) { - return moves.filter(m => m.vanish.length == 2 && m.appear.length == 1); + return moves.filter(m => m.vanish.length == 2); + } + + getPotentialKnightMoves(sq) { + // Knight becomes knightrider: + return this.getSlideNJumpMoves(sq, V.steps[V.KNIGHT]); + } + + getPotentialKingMoves(sq) { + // King become queen: + return ( + this.getSlideNJumpMoves(sq, V.steps[V.ROOK].concat(V.steps[V.BISHOP])); + ) } getAllPotentialMoves() { @@ -88,9 +104,7 @@ export class MonochromeRules extends ChessRules { for (let j = 0; j < V.size.y; j++) { if ( this.board[i][j] != V.EMPTY && - this.getPotentialMovesFrom([i, j]).some(m => - // Warning: discard castle moves - m.vanish.length == 2 && m.appear.length == 1) + this.getPotentialMovesFrom([i, j]).some(m => m.vanish.length == 2) ) { return true; } @@ -120,7 +134,7 @@ export class MonochromeRules extends ChessRules { } getCurrentScore() { - // Is there anything in my half board? + // Is there anything in opponent's half board? const color = V.GetOppCol(this.turn); const xBounds = color == 'w' ? [4,7] : [0,3]; let nothingHere = true; @@ -138,8 +152,8 @@ export class MonochromeRules extends ChessRules { } static GenRandInitFen(randomness) { - // Remove the en-passant part of the FEN - const fen = ChessRules.GenRandInitFen(randomness).slice(0, -2); + // Remove the en-passant + castle part of the FEN + const fen = ChessRules.GenRandInitFen(randomness).slice(0, -6); const firstSpace = fen.indexOf(' '); return ( fen.substr(0, firstSpace).replace(/[A-Z]/g, (c) => c.toLowerCase()) + @@ -164,4 +178,33 @@ export class MonochromeRules extends ChessRules { } return evaluation; } + + getNotation(move) { + // Translate initial square (because pieces may fly unusually!) + const initialSquare = V.CoordsToSquare(move.start); + + // Translate final square + const finalSquare = V.CoordsToSquare(move.end); + + let notation = ""; + const piece = this.getPiece(move.start.x, move.start.y); + if (piece == V.PAWN) { + // pawn move (TODO: enPassant indication) + if (move.vanish.length == 2) { + // capture + notation = initialSquare + "x" + finalSquare; + } + else notation = finalSquare; + if (piece != move.appear[0].p) + //promotion + notation += "=" + move.appear[0].p.toUpperCase(); + } + else { + // Piece movement + notation = piece.toUpperCase(); + if (move.vanish.length > 1) notation += initialSquare + "x"; + notation += finalSquare; + } + return notation; + } };