Fixed Crazyhouse; still have to keep track of promoted pawns
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 28 Nov 2018 16:28:13 +0000 (17:28 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 28 Nov 2018 16:28:13 +0000 (17:28 +0100)
TODO
public/javascripts/components/game.js
public/javascripts/variants/Crazyhouse.js
views/rules/Crazyhouse.pug

diff --git a/TODO b/TODO
index fe7d847..58906a8 100644 (file)
--- a/TODO
+++ b/TODO
@@ -4,3 +4,4 @@ setInterval "CRON" task in sockets.js to check connected clients
 (every 1hour maybe, or more)
 Systematically show init+dest squares in PGN, maybe after short notation
 (2 moves list, second for de-ambiguification)
+Crazyhouse: keep track of promoted pawns.
index 2897b1c..f5bef8e 100644 (file)
@@ -240,38 +240,75 @@ Vue.component('my-game', {
                                );
                        }
                        elementArray.push(gameDiv);
-                       if (!!this.vr.reserve) //TODO: table, show counts for reserve pieces
-                               //<tr style="padding:0">
-                               //    <td style="padding:0;font-size:10px">3</td>
+                       if (!!this.vr.reserve)
                        {
-                               let reservePiecesArray = [];
+                               let myReservePiecesArray = [];
                                for (let i=0; i<VariantRules.RESERVE_PIECES.length; i++)
                                {
-                                       reservePiecesArray.push(h('img',
+                                       myReservePiecesArray.push(h('div',
+                                       {
+                                               'class': {'board':true, ['board'+sizeY]:true},
+                                               attrs: { id: this.getSquareId({x:sizeX,y:i}) }
+                                       },
+                                       [
+                                               h('img',
                                                {
                                                        'class': {"piece":true},
                                                        attrs: {
                                                                "src": "/images/pieces/" +
                                                                        this.vr.getReservePpath(this.mycolor,i) + ".svg",
-                                                               id: this.getSquareId({x:sizeX,y:i}),
                                                        }
-                                               })
-                                       );
+                                               }),
+                                               h('sup',
+                                                       {style: { "padding-left":"40%"} },
+                                                       [ this.vr.reserve[this.mycolor][VariantRules.RESERVE_PIECES[i]] ]
+                                               )
+                                       ]));
                                }
-                               let reserve = h('div',
-                                       {'class':{'game':true}}, [
+                               let oppReservePiecesArray = [];
+                               const oppCol = this.vr.getOppCol(this.mycolor);
+                               for (let i=0; i<VariantRules.RESERVE_PIECES.length; i++)
+                               {
+                                       oppReservePiecesArray.push(h('div',
+                                       {
+                                               'class': {'board':true, ['board'+sizeY]:true},
+                                               attrs: { id: this.getSquareId({x:sizeX,y:i}) }
+                                       },
+                                       [
+                                               h('img',
+                                               {
+                                                       'class': {"piece":true},
+                                                       attrs: {
+                                                               "src": "/images/pieces/" +
+                                                                       this.vr.getReservePpath(oppCol,i) + ".svg",
+                                                       }
+                                               }),
+                                               h('sup',
+                                                       {style: { "padding-left":"40%"} },
+                                                       [ this.vr.reserve[oppCol][VariantRules.RESERVE_PIECES[i]] ]
+                                               )
+                                       ]));
+                               }
+                               let reserves = h('div',
+                                       {
+                                               'class':{'game':true},
+                                               style: {"margin-bottom": "20px"},
+                                       },
+                                       [
+                                               h('div',
+                                                       {
+                                                               'class': { 'row': true },
+                                                               style: {"margin-bottom": "15px"},
+                                                       },
+                                                       myReservePiecesArray
+                                               ),
                                                h('div',
                                                        { 'class': { 'row': true }},
-                                                       [
-                                                               h('div',
-                                                                       {'class':{'board':true, ['board'+sizeY]:true}},
-                                                                       reservePiecesArray
-                                                               )
-                                                       ]
+                                                       oppReservePiecesArray
                                                )
-                                       ],
+                                       ]
                                );
-                               elementArray.push(reserve);
+                               elementArray.push(reserves);
                        }
                        const eogMessage = this.getEndgameMessage(this.score);
                        const modalEog = [
index 9cb0768..9558fe4 100644 (file)
@@ -31,6 +31,22 @@ class CrazyhouseRules extends ChessRules
                        else if (m.vanish.length == 0)
                                this.reserve[m.appear[0].c][m.appear[0].p]--;
                });
+               // TODO: keep track of promoted pawns ==> give a pawn if captured.
+       }
+
+       getColor(i,j)
+       {
+               const sizeX = VariantRules.size[0];
+               if (i >= sizeX)
+                       return (i==sizeX ? "w" : "b");
+               return this.board[i][j].charAt(0);
+       }
+       getPiece(i,j)
+       {
+               const sizeX = VariantRules.size[0];
+               if (i >= sizeX)
+                       return VariantRules.RESERVE_PIECES[j];
+               return this.board[i][j].charAt(1);
        }
 
        // Used by the interface:
@@ -52,11 +68,13 @@ class CrazyhouseRules extends ChessRules
                if (this.reserve[color][p] == 0)
                        return [];
                let moves = [];
-               for (let i=0; i<sizeX; i++)
+               const [sizeX,sizeY] = VariantRules.size;
+               const pawnShift = (p==VariantRules.PAWN ? 1 : 0);
+               for (let i=pawnShift; i<sizeX-pawnShift; i++)
                {
                        for (let j=0; j<sizeY; j++)
                        {
-                               if (this.board[i][j] != VariantRules.EMPTY)
+                               if (this.board[i][j] == VariantRules.EMPTY)
                                {
                                        let mv = new Move({
                                                appear: [
@@ -66,7 +84,10 @@ class CrazyhouseRules extends ChessRules
                                                                c: color,
                                                                p: p
                                                        })
-                                               ]
+                                               ],
+                                               vanish: [],
+                                               start: {x:sizeX, y:y}, //a bit artificial...
+                                               end: {x:i, y:j}
                                        });
                                        moves.push(mv);
                                }
@@ -116,7 +137,7 @@ class CrazyhouseRules extends ChessRules
                super.updateVariables(move);
                const color = this.turn;
                if (move.vanish.length==2)
-                       this.reserve[color][move.appear[0].p]++;
+                       this.reserve[color][move.vanish[1].p]++;
                if (move.vanish.length==0)
                        this.reserve[color][move.appear[0].p]--;
        }
@@ -126,7 +147,7 @@ class CrazyhouseRules extends ChessRules
                super.unupdateVariables(move);
                const color = this.turn;
                if (move.vanish.length==2)
-                       this.reserve[color][move.appear[0].p]--;
+                       this.reserve[color][move.vanish[1].p]--;
                if (move.vanish.length==0)
                        this.reserve[color][move.appear[0].p]++;
        }
@@ -139,7 +160,7 @@ class CrazyhouseRules extends ChessRules
                        return super.getNotation(move);
                // Rebirth:
                const piece =
-                       (move.appear[0].p != VariantRules.PAWN ? move.appear.p.toUpperCase() : "");
+                       (move.appear[0].p != VariantRules.PAWN ? move.appear[0].p.toUpperCase() : "");
                const finalSquare =
                        String.fromCharCode(97 + move.end.y) + (VariantRules.size[0]-move.end.x);
                return piece + "@" + finalSquare;
index 3928c30..5566bee 100644 (file)
@@ -25,6 +25,8 @@ p.
        not the promoted piece. This is to allow to gain material on last rank without
        fear of giving a queen to the opponent.
 
+p.warn This detail is not implemented yet (will be very soon).
+
 h3 Credits
 
 p