From: Benjamin Auder Date: Mon, 24 Feb 2020 14:52:36 +0000 (+0100) Subject: HiddenRules almost OK (need to ignore checks. Position kings on first rank?). window... X-Git-Url: https://git.auder.net/doc/html/bundles/framework/pieces/cr.svg?a=commitdiff_plain;h=b91392511d5df54b0e3cd5fcf439471cc6767804;p=vchess.git HiddenRules almost OK (need to ignore checks. Position kings on first rank?). window.V reactive in BaseGame? --- diff --git a/client/public/images/pieces/Hidden/Question_mark_alternate.svg b/client/public/images/pieces/Hidden/Question_mark_alternate.svg new file mode 100644 index 00000000..f88ab1e3 --- /dev/null +++ b/client/public/images/pieces/Hidden/Question_mark_alternate.svg @@ -0,0 +1,28 @@ + + + + + + + + + + + diff --git a/client/public/images/pieces/Hidden/bp.svg b/client/public/images/pieces/Hidden/bp.svg new file mode 100644 index 00000000..ba3ff2ef --- /dev/null +++ b/client/public/images/pieces/Hidden/bp.svg @@ -0,0 +1,68 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/client/public/images/pieces/Hidden/wp.svg b/client/public/images/pieces/Hidden/wp.svg new file mode 100644 index 00000000..c7792aa8 --- /dev/null +++ b/client/public/images/pieces/Hidden/wp.svg @@ -0,0 +1,88 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index 42fe1897..07f6bba6 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -104,11 +104,16 @@ export default { cursor: -1, //index of the move just played lastMove: null, firstMoveNumber: 0, //for printing - incheck: [] //for Board + incheck: [], //for Board + V: null // TODO: need "local" V to trigger re-computation of computed properties ? + // --> le passer depuis CompGame ou Game comme une property ?! }; }, watch: { // game initial FEN changes when a new game starts + + // TODO: this watcher is obsolete ? + "game.fenStart": function() { this.re_setVariables(); }, diff --git a/client/src/variants/Hidden.js b/client/src/variants/Hidden.js index 1836352a..99b4a7a6 100644 --- a/client/src/variants/Hidden.js +++ b/client/src/variants/Hidden.js @@ -1,4 +1,4 @@ -import { ChessRules } from "@/base_rules"; +import { ChessRules, PiPo, Move } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; @@ -46,6 +46,14 @@ export const VariantRules = class HiddenRules extends ChessRules { return ChessRules.PIECES.concat(Object.values(V.HIDDEN_CODE)); } + // Pieces can be hidden :) + getPiece(i, j) { + const piece = this.board[i][j].charAt(1); + if (Object.keys(V.HIDDEN_DECODE).includes(piece)) + return V.HIDDEN_DECODE[piece]; + return piece; + } + // Scan board for kings positions (no castling) scanKingsRooks(fen) { this.kingPos = { w: [-1, -1], b: [-1, -1] }; @@ -84,9 +92,53 @@ export const VariantRules = class HiddenRules extends ChessRules { return b; } - //getPotentialMovesFrom: TODO: write + getBasicMove([sx, sy], [ex, ey], tr) { + 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 + if (Object.keys(V.HIDDEN_DECODE).includes(mv.appear[0].p)) + mv.appear[0].p = V.HIDDEN_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" + ); + } - // TODO: bishops on different colors, a1 --> h1, h2 --> a2 ? static GenRandInitFen() { let pieces = { w: new Array(8), b: new Array(8) }; // Shuffle pieces + pawns on two first ranks @@ -111,36 +163,43 @@ export const VariantRules = class HiddenRules extends ChessRules { const knight2Pos = positions[randIndex]; positions.splice(randIndex, 1); - // Get random square for queen + // 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 squares for pawns - // TODO... + // Get random square for queen + randIndex = randInt(9); + const kingPos = positions[randIndex]; + positions.splice(randIndex, 1); - // Rooks and king positions are now fixed, - // because of the ordering rook-king-rook - const rook1Pos = positions[0]; - const kingPos = positions[1]; - const rook2Pos = positions[2]; + // 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] = "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"; + 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"; } - return ( - pieces["b"].join("") + - "/pppppppp/8/8/8/8/PPPPPPPP/" + - pieces["w"].join("").toUpperCase() + - " w 0" - ); + let upFen = pieces["b"].join(""); + upFen = upFen.substr(0,8) + "/" + upFen.substr(8); + let downFen = pieces["b"].join("").toUpperCase(); + downFen = downFen.substr(0,8) + "/" + downFen.substr(8); + return upFen + "/8/8/8/8/" + downFen + " w 0"; } getCheckSquares() { diff --git a/client/src/views/Rules.vue b/client/src/views/Rules.vue index 015df7b3..a8edf8f5 100644 --- a/client/src/views/Rules.vue +++ b/client/src/views/Rules.vue @@ -57,7 +57,8 @@ export default { gameInfo: { vname: "", mode: "versus", - } + }, + V: null, }; }, watch: { @@ -71,7 +72,7 @@ export default { }, computed: { showAnalyzeBtn: function() { - return (this.display=='rules' && (!window.V || V.CanAnalyze)); + return (this.display=='rules' && (!this.V || this.V.CanAnalyze)); }, content: function() { if (!this.gameInfo.vname) return ""; //variant not set yet @@ -112,7 +113,7 @@ export default { }, re_setVariant: async function(vname) { const vModule = await import("@/variants/" + vname + ".js"); - window.V = vModule.VariantRules; + this.V = window.V = vModule.VariantRules; this.gameInfo.vname = vname; }, startGame: function(mode) {