- toNewKingPos(move) {
- for (let a of move.appear)
- if (a.p == V.KING) this.kingPos[a.c] = [a.x, a.y];
- }
-
- postPlay(move) {
- if (move.start.x < 0) return;
- this.toNewKingPos(move);
- this.updateCastleFlags(move);
- }
-
- updateCastleFlags(move) {
- const firstRank = { 'w': V.size.x - 1, 'b': 0 };
- for (let v of move.vanish) {
- if (v.p == V.KING) this.castleFlags[v.c] = [V.size.y, V.size.y];
- else if (v.x == firstRank[v.c] && this.castleFlags[v.c].includes(v.y)) {
- const flagIdx = (v.y == this.castleFlags[v.c][0] ? 0 : 1);
- this.castleFlags[v.c][flagIdx] = V.size.y;
- }
- }
- }
-
- undo(move) {
- if (!!move.ignore) return; //TODO: remove that later
- this.disaggregateFlags(JSON.parse(move.flags));
- V.UndoOnBoard(this.board, move);
- if (this.subTurn == 1) {
- this.amoves.pop();
- this.turn = V.GetOppCol(this.turn);
- this.movesCount--;
- }
- if (move.subTurn == 1) this.firstMove.pop();
- this.subTurn = move.subTurn;
- this.toOldKingPos(move);
- }
-
- toOldKingPos(move) {
- // (Potentially) Reset king position
- for (let v of move.vanish)
- if (v.p == V.KING) this.kingPos[v.c] = [v.x, v.y];
- }
-