- // NOTE: no (un)updateVariables() because no computer mode
- // --> but isEnlightened() should have its variable updated
- // --> in fact an array is enough (no need for a function)
- // recomputed after every play/undo (although there are no undo here for now)
+ updateVariables(move)
+ {
+ // Update kings positions
+ const piece = move.vanish[0].p;
+ const c = move.vanish[0].c;
+ if (piece == V.KING && move.appear.length > 0)
+ {
+ this.kingPos[c][0] = move.appear[0].x;
+ this.kingPos[c][1] = move.appear[0].y;
+ }
+ if (move.vanish.length >= 2 && move.vanish[1].p == V.KING)
+ {
+ // We took opponent king !
+ const oppCol = this.getOppCol(c);
+ this.kingPos[oppCol] = [-1,-1];
+ }
+
+ // Update moves for both colors:
+ this.updateEnlightened();
+ }
+
+ unupdateVariables(move)
+ {
+ super.unupdateVariables(move);
+ const c = move.vanish[0].c;
+ const oppCol = this.getOppCol(c);
+ if (this.kingPos[oppCol][0] < 0)
+ {
+ // Last move took opponent's king
+ for (let psq of move.vanish)
+ {
+ if (psq.p == 'k')
+ {
+ this.kingPos[oppCol] = [psq.x, psq.y];
+ break;
+ }
+ }
+ }
+
+ // Update moves for both colors:
+ this.updateEnlightened();
+ }