From: Benjamin Auder Date: Mon, 19 Nov 2018 17:20:27 +0000 (+0100) Subject: Draft of Antiking variant X-Git-Url: https://git.auder.net/js/current/app_dev.php/index.css?a=commitdiff_plain;h=7d6b0773c093ad4347ff8b444236e7d89b06977e;p=vchess.git Draft of Antiking variant --- diff --git a/public/images/pieces/Antiking/ba.svg b/public/images/pieces/Antiking/ba.svg new file mode 100644 index 00000000..27fc9b39 --- /dev/null +++ b/public/images/pieces/Antiking/ba.svg @@ -0,0 +1,98 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/public/images/pieces/Antiking/wa.svg b/public/images/pieces/Antiking/wa.svg new file mode 100644 index 00000000..cb86a775 --- /dev/null +++ b/public/images/pieces/Antiking/wa.svg @@ -0,0 +1,98 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 3eb27f27..147aeafe 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -668,7 +668,7 @@ Vue.component('my-game', { this.selectedPiece.style.display = "inline-block"; this.selectedPiece.style.zIndex = 3000; let startSquare = this.getSquareFromId(e.target.parentNode.id); - this.possibleMoves = this.vr.canIplay(this.mycolor,startSquare) + this.possibleMoves = this.mode!="idle" && this.vr.canIplay(this.mycolor,startSquare) ? this.vr.getPossibleMovesFrom(startSquare) : []; e.target.parentNode.appendChild(this.selectedPiece); diff --git a/public/javascripts/variants/Antiking.js b/public/javascripts/variants/Antiking.js new file mode 100644 index 00000000..ddfd9677 --- /dev/null +++ b/public/javascripts/variants/Antiking.js @@ -0,0 +1,173 @@ +class AntikingRules +{ + // Path to pieces + static getPpath(b) + { + return b[1]=='a' ? "Antiking/"+b : b; + } + + static get ANTIKING() { return 'a'; } + + // TODO: more subtle than that, require changing args: wp, bk and not just colors + canTake(color1, color2) + { + return color1 != color2; + } + + getPotentialMovesFrom([x,y]) + { + let c = this.getColor(x,y); + switch (this.getPiece(x,y)) + { + case VariantRules.ANTIKING: + return this.getPotentialAntikingMoves(x,y,c); + default: + return super.getPotentielMovesFrom([x,y]); + } + } + + getPotentialAntikingMoves(x, y, c) + { + // TODO + } + +// TODO: need to re-think some logic, since antikings capture same color + + isAttacked(sq, color) + { + return (this.isAttackedByPawn(sq, color) + || this.isAttackedByRook(sq, color) + || this.isAttackedByKnight(sq, color) + || this.isAttackedByBishop(sq, color) + || this.isAttackedByQueen(sq, color) + || this.isAttackedByKing(sq, color)); //... + } + + isAttackedByAntiking(sq, color) + { + // TODO + } + + underCheck(move, c) + { + this.play(move); + let res = this.isAttacked(this.kingPos[c], this.getOppCol(c)); + // TODO: also check that antiking is still in check + this.undo(move); + return res; + } + + getCheckSquares(move, c) + { + this.play(move); + // TODO + let res = this.isAttacked(this.kingPos[c], this.getOppCol(c)) + ? [ JSON.parse(JSON.stringify(this.kingPos[c])) ] //need to duplicate! + : [ ]; + this.undo(move); + return res; + } + + // Apply a move on board + static PlayOnBoard(board, move) + { + for (let psq of move.vanish) + board[psq.x][psq.y] = VariantRules.EMPTY; + for (let psq of move.appear) + board[psq.x][psq.y] = psq.c + psq.p; + } + // Un-apply the played move + static UndoOnBoard(board, move) + { + for (let psq of move.appear) + board[psq.x][psq.y] = VariantRules.EMPTY; + for (let psq of move.vanish) + board[psq.x][psq.y] = psq.c + psq.p; + } + + // TODO: need antikingPos as well + updateVariables(move) + { + // ... + } + + unupdateVariables(move) + { + // TODO + } + + checkGameEnd(color) + { + // TODO + if (!this.isAttacked(this.kingPos[color], this.getOppCol(color))) + return "1/2"; + return color == "w" ? "0-1" : "1-0"; + } + + // Pieces values + static get VALUES() { + return { + 'p': 1, + 'r': 5, + 'n': 3, + 'b': 3, + 'q': 9, + 'k': 1000, + 'a': 1000 + }; + } + + static GenRandInitFen() + { + // TODO: no need all code, just add an antiking at rondom on 3rd ranks + let pieces = [new Array(8), new Array(8)]; + // Shuffle pieces on first and last rank + for (let c = 0; c <= 1; c++) + { + let positions = _.range(8); + + // Get random squares for bishops + let randIndex = 2 * _.random(3); + let bishop1Pos = positions[randIndex]; + // The second bishop must be on a square of different color + let randIndex_tmp = 2 * _.random(3) + 1; + let 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 = _.random(5); + let knight1Pos = positions[randIndex]; + positions.splice(randIndex, 1); + randIndex = _.random(4); + let knight2Pos = positions[randIndex]; + positions.splice(randIndex, 1); + + // Get random square for queen + randIndex = _.random(3); + let queenPos = positions[randIndex]; + positions.splice(randIndex, 1); + + // Rooks and king positions are now fixed, because of the ordering rook-king-rook + let rook1Pos = positions[0]; + let kingPos = positions[1]; + let rook2Pos = positions[2]; + + // Finally put the shuffled pieces in the board array + pieces[c][rook1Pos] = 'r'; + pieces[c][knight1Pos] = 'n'; + pieces[c][bishop1Pos] = 'b'; + pieces[c][queenPos] = 'q'; + pieces[c][kingPos] = 'k'; + pieces[c][bishop2Pos] = 'b'; + pieces[c][knight2Pos] = 'n'; + pieces[c][rook2Pos] = 'r'; + } + let fen = pieces[0].join("") + + "/pppppppp/8/8/8/8/PPPPPPPP/" + + pieces[1].join("").toUpperCase() + + " 1111"; //add flags + return fen; + } +}