From: Benjamin Auder Date: Tue, 4 Dec 2018 18:22:23 +0000 (+0100) Subject: Adjust comments, add a few TODOs + remove DEBUG in play/undo X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/css/current/pieces/cb.svg?a=commitdiff_plain;h=dda21a71b6245832a78ca987b14c77176bd15dd6;p=vchess.git Adjust comments, add a few TODOs + remove DEBUG in play/undo --- diff --git a/TODO b/TODO index 7271a907..1aae2fb1 100644 --- a/TODO +++ b/TODO @@ -3,5 +3,4 @@ For animation, moves should contains "moving" and "fading" maybe... setInterval "CRON" task in sockets.js to check connected clients (every 1hour maybe, or more) Button to show all pieces that can move (next to expert mode; change icons) -Style (crazyhouse): ghost image of reserve pieces are initially translated Some bots are very weak, others quite slow... diff --git a/package.json b/package.json index ee95dd53..62092276 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "vc", - "version": "0.0.0", + "name": "vchess", + "version": "0.1.0", "private": true, "scripts": { "start": "gulp start" diff --git a/public/images/pieces/new/Chess_Alt26.svg b/public/images/pieces/_originals/Chess_Alt26.svg similarity index 100% rename from public/images/pieces/new/Chess_Alt26.svg rename to public/images/pieces/_originals/Chess_Alt26.svg diff --git a/public/images/pieces/new/Chess_Gdt45.svg b/public/images/pieces/_originals/Chess_Gdt45.svg similarity index 100% rename from public/images/pieces/new/Chess_Gdt45.svg rename to public/images/pieces/_originals/Chess_Gdt45.svg diff --git a/public/images/pieces/new/Chess_Gll45.svg b/public/images/pieces/_originals/Chess_Gll45.svg similarity index 100% rename from public/images/pieces/new/Chess_Gll45.svg rename to public/images/pieces/_originals/Chess_Gll45.svg diff --git a/public/images/pieces/new/Chess_Ult45.svg b/public/images/pieces/_originals/Chess_Ult45.svg similarity index 100% rename from public/images/pieces/new/Chess_Ult45.svg rename to public/images/pieces/_originals/Chess_Ult45.svg diff --git a/public/images/pieces/new/Chess_Zdl45.svg b/public/images/pieces/_originals/Chess_Zdl45.svg similarity index 100% rename from public/images/pieces/new/Chess_Zdl45.svg rename to public/images/pieces/_originals/Chess_Zdl45.svg diff --git a/public/images/pieces/new/Chess_Zll45.svg b/public/images/pieces/_originals/Chess_Zll45.svg similarity index 100% rename from public/images/pieces/new/Chess_Zll45.svg rename to public/images/pieces/_originals/Chess_Zll45.svg diff --git a/public/images/pieces/new/Chess_adt45.svg b/public/images/pieces/_originals/Chess_adt45.svg similarity index 100% rename from public/images/pieces/new/Chess_adt45.svg rename to public/images/pieces/_originals/Chess_adt45.svg diff --git a/public/images/pieces/new/Chess_alt45.svg b/public/images/pieces/_originals/Chess_alt45.svg similarity index 100% rename from public/images/pieces/new/Chess_alt45.svg rename to public/images/pieces/_originals/Chess_alt45.svg diff --git a/public/images/pieces/new/Chess_clt45.svg b/public/images/pieces/_originals/Chess_clt45.svg similarity index 100% rename from public/images/pieces/new/Chess_clt45.svg rename to public/images/pieces/_originals/Chess_clt45.svg diff --git a/public/images/pieces/new/camel-animal-pet-desert-39f82768c72363eb.svg b/public/images/pieces/_originals/camel-animal-pet-desert-39f82768c72363eb.svg similarity index 100% rename from public/images/pieces/new/camel-animal-pet-desert-39f82768c72363eb.svg rename to public/images/pieces/_originals/camel-animal-pet-desert-39f82768c72363eb.svg diff --git a/public/images/pieces/new/camel-animal-pet-desert-3f04e77f40eba40d.svg b/public/images/pieces/_originals/camel-animal-pet-desert-3f04e77f40eba40d.svg similarity index 100% rename from public/images/pieces/new/camel-animal-pet-desert-3f04e77f40eba40d.svg rename to public/images/pieces/_originals/camel-animal-pet-desert-3f04e77f40eba40d.svg diff --git a/public/images/pieces/new/camel-animal-wildlife-34b2662eb81cfec3.svg b/public/images/pieces/_originals/camel-animal-wildlife-34b2662eb81cfec3.svg similarity index 100% rename from public/images/pieces/new/camel-animal-wildlife-34b2662eb81cfec3.svg rename to public/images/pieces/_originals/camel-animal-wildlife-34b2662eb81cfec3.svg diff --git a/public/images/pieces/new/camel-animal-wildlife-3b15afb5e788b9ec.svg b/public/images/pieces/_originals/camel-animal-wildlife-3b15afb5e788b9ec.svg similarity index 100% rename from public/images/pieces/new/camel-animal-wildlife-3b15afb5e788b9ec.svg rename to public/images/pieces/_originals/camel-animal-wildlife-3b15afb5e788b9ec.svg diff --git a/public/images/pieces/new/unicorn-myth-legend-halloween-fantasy-37ec614cb63bc127.svg b/public/images/pieces/_originals/unicorn-myth-legend-halloween-fantasy-37ec614cb63bc127.svg similarity index 100% rename from public/images/pieces/new/unicorn-myth-legend-halloween-fantasy-37ec614cb63bc127.svg rename to public/images/pieces/_originals/unicorn-myth-legend-halloween-fantasy-37ec614cb63bc127.svg diff --git a/public/images/pieces/new/wildebeest-animal-wild-wildlife-face-326845431b848a31.svg b/public/images/pieces/_originals/wildebeest-animal-wild-wildlife-face-326845431b848a31.svg similarity index 100% rename from public/images/pieces/new/wildebeest-animal-wild-wildlife-face-326845431b848a31.svg rename to public/images/pieces/_originals/wildebeest-animal-wild-wildlife-face-326845431b848a31.svg diff --git a/public/images/pieces/new/wildebeest-animal-wildlife-31b7b8fe2ffee150.svg b/public/images/pieces/_originals/wildebeest-animal-wildlife-31b7b8fe2ffee150.svg similarity index 100% rename from public/images/pieces/new/wildebeest-animal-wildlife-31b7b8fe2ffee150.svg rename to public/images/pieces/_originals/wildebeest-animal-wildlife-31b7b8fe2ffee150.svg diff --git a/public/javascripts/base_rules.js b/public/javascripts/base_rules.js index 6bc3591c..79b6a7a3 100644 --- a/public/javascripts/base_rules.js +++ b/public/javascripts/base_rules.js @@ -124,7 +124,7 @@ class ChessRules return board; } - // Overridable: flags can change a lot + // Extract (relevant) flags from fen setFlags(fen) { // white a-castle, h-castle, black a-castle, h-castle @@ -137,7 +137,6 @@ class ChessRules /////////////////// // GETTERS, SETTERS - // Simple useful getters static get size() { return [8,8]; } // Two next functions return 'undefined' if called on empty square getColor(i,j) { return this.board[i][j].charAt(0); } @@ -199,7 +198,7 @@ class ChessRules return undefined; //default } - // can thing on square1 take thing on square2 + // Can thing on square1 take thing on square2 canTake([x1,y1], [x2,y2]) { return this.getColor(x1,y1) != this.getColor(x2,y2); @@ -291,7 +290,7 @@ class ChessRules return moves; } - // What are the pawn moves from square x,y considering color "color" ? + // What are the pawn moves from square x,y ? getPotentialPawnMoves([x,y]) { const color = this.turn; @@ -546,7 +545,7 @@ class ChessRules return false; } - // Check if pieces of color 'colors' are attacking square x,y + // Check if pieces of color in array 'colors' are attacking square x,y isAttacked(sq, colors) { return (this.isAttackedByPawn(sq, colors) @@ -557,7 +556,7 @@ class ChessRules || this.isAttackedByKing(sq, colors)); } - // Is square x,y attacked by pawns of color c ? + // Is square x,y attacked by 'colors' pawns ? isAttackedByPawn([x,y], colors) { const [sizeX,sizeY] = VariantRules.size; @@ -579,28 +578,28 @@ class ChessRules return false; } - // Is square x,y attacked by rooks of color c ? + // Is square x,y attacked by 'colors' rooks ? isAttackedByRook(sq, colors) { return this.isAttackedBySlideNJump(sq, colors, VariantRules.ROOK, VariantRules.steps[VariantRules.ROOK]); } - // Is square x,y attacked by knights of color c ? + // Is square x,y attacked by 'colors' knights ? isAttackedByKnight(sq, colors) { return this.isAttackedBySlideNJump(sq, colors, VariantRules.KNIGHT, VariantRules.steps[VariantRules.KNIGHT], "oneStep"); } - // Is square x,y attacked by bishops of color c ? + // Is square x,y attacked by 'colors' bishops ? isAttackedByBishop(sq, colors) { return this.isAttackedBySlideNJump(sq, colors, VariantRules.BISHOP, VariantRules.steps[VariantRules.BISHOP]); } - // Is square x,y attacked by queens of color c ? + // Is square x,y attacked by 'colors' queens ? isAttackedByQueen(sq, colors) { const V = VariantRules; @@ -608,7 +607,7 @@ class ChessRules V.steps[V.ROOK].concat(V.steps[V.BISHOP])); } - // Is square x,y attacked by king of color c ? + // Is square x,y attacked by 'colors' king(s) ? isAttackedByKing(sq, colors) { const V = VariantRules; @@ -617,7 +616,7 @@ class ChessRules } // Generic method for non-pawn pieces ("sliding or jumping"): - // is x,y attacked by piece !of color in colors? + // is x,y attacked by a piece of color in array 'colors' ? isAttackedBySlideNJump([x,y], colors, piece, steps, oneStep) { const [sizeX,sizeY] = VariantRules.size; @@ -640,7 +639,7 @@ class ChessRules return false; } - // Is color c under check after move ? + // Is current player under check after his move ? underCheck(move) { const color = this.turn; @@ -650,7 +649,7 @@ class ChessRules return res; } - // On which squares is color c under check (after move) ? + // On which squares is opponent under check after our move ? getCheckSquares(move) { this.play(move); @@ -711,6 +710,8 @@ class ChessRules } } + // After move is undo-ed, un-update variables (flags are reset) + // TODO: more symmetry, by storing flags increment in move... unupdateVariables(move) { // (Potentially) Reset king position @@ -721,12 +722,6 @@ class ChessRules play(move, ingame) { - // DEBUG: -// if (!this.states) this.states = []; -// if (!ingame) this.states.push(JSON.stringify(this.board)); -// if (!this.rstates) this.rstates = []; -// if (!ingame) this.rstates.push(JSON.stringify(this.promoted)+"-"+JSON.stringify(this.reserve)); - if (!!ingame) move.notation = [this.getNotation(move), this.getLongNotation(move)]; @@ -744,23 +739,16 @@ class ChessRules this.moves.pop(); this.unupdateVariables(move); this.parseFlags(JSON.parse(move.flags)); - - // DEBUG: -// let state = this.states.pop(); -// let rstate = this.rstates.pop(); -// if (JSON.stringify(this.board) != state || JSON.stringify(this.promoted)+"-"+JSON.stringify(this.reserve) != rstate) -// debugger; } ////////////// // END OF GAME + // Basic check for 3 repetitions (in the last moves only) checkRepetition() { - // Check for 3 repetitions if (this.moves.length >= 8) { - // NOTE: crude detection, only moves repetition const L = this.moves.length; if (_.isEqual(this.moves[L-1], this.moves[L-5]) && _.isEqual(this.moves[L-2], this.moves[L-6]) && @@ -773,6 +761,7 @@ class ChessRules return false; } + // Is game over ? And if yes, what is the score ? checkGameOver() { if (this.checkRepetition()) @@ -900,6 +889,7 @@ class ChessRules return moves1[_.sample(candidates, 1)]; } + // TODO: some optimisations, understand why CH get mated in 2 alphabeta(depth, alpha, beta) { const maxeval = VariantRules.INFINITY; @@ -965,7 +955,7 @@ class ChessRules //////////// // FEN utils - // Overridable.. + // Setup the initial random (assymetric) position static GenRandInitFen() { let pieces = [new Array(8), new Array(8)]; @@ -1025,6 +1015,7 @@ class ChessRules return this.getBaseFen() + " " + this.getFlagsFen(); } + // Position part of the FEN string getBaseFen() { let fen = ""; @@ -1058,7 +1049,7 @@ class ChessRules return fen; } - // Overridable.. + // Flags part of the FEN string getFlagsFen() { let fen = ""; diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 04185a78..72b5da90 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -432,7 +432,7 @@ Vue.component('my-game', { "col-lg-6":true, "col-lg-offset-3":true, }, - // NOTE: click = mousedown + mouseup --> what about smartphone?! + // NOTE: click = mousedown + mouseup on: { mousedown: this.mousedown, mousemove: this.mousemove,