9b62150b8baffe25531aa31818801106ea4619e9
1 import ChessRules
from "/base_rules";
2 import GiveawayRules
from "/variants/Giveaway";
3 import { ArrayFun
} from "/utils/array.js";
4 import { Random
} from "/utils/alea.js";
5 import PiPo
from "/utils/PiPo.js";
6 import Move
from "/utils/Move.js";
8 export class ChakartRules
extends ChessRules
{
10 static get Options() {
15 variable: "randomness",
18 { label: "Deterministic", value: 0 },
19 { label: "Symmetric random", value: 1 },
20 { label: "Asymmetric random", value: 2 }
27 get pawnPromotions() {
28 return ['q', 'r', 'n', 'b', 'k'];
38 static get IMMOBILIZE_CODE() {
49 static get IMMOBILIZE_DECODE() {
60 static get INVISIBLE_QUEEN() {
64 // Fictive color 'a', bomb banana mushroom egg
69 return 'd'; //"Donkey"
74 static get MUSHROOM() {
78 genRandInitFen(seed
) {
79 const gr
= new GiveawayRules({mode: "suicide"}, true);
81 gr
.genRandInitFen(seed
).slice(0, -1) +
82 // Add Peach + Mario flags + capture counts
83 '{"flags": "1111", "ccount": "000000000000"}'
90 ? "w" + f
.toLowerCase()
91 : (['w', 'd', 'e', 'm'].includes(f
) ? "a" : "b") + f
96 // King can send shell? Queen can be invisible?
98 w: {k: false, q: false},
99 b: {k: false, q: false}
101 for (let c
of ['w', 'b']) {
102 for (let p
of ['k', 'q']) {
103 this.powerFlags
[c
][p
] =
104 fenflags
.charAt((c
== "w" ? 0 : 2) + (p
== 'k' ? 0 : 1)) == "1";
110 return this.powerFlags
;
113 disaggregateFlags(flags
) {
114 this.powerFlags
= flags
;
118 return super.getFen() + " " + this.getCapturedFen();
122 return ['w', 'b'].map(c
=> {
123 return ['k', 'q'].map(p
=> this.powerFlags
[c
][p
] ? "1" : "0").join("");
128 const res
= ['w', 'b'].map(c
=> {
129 Object
.values(this.captured
[c
])
131 return res
[0].concat(res
[1]).join("");
134 setOtherVariables(fenParsed
) {
135 super.setOtherVariables(fenParsed
);
136 // Initialize captured pieces' counts from FEN
137 const allCapts
= fenParsed
.captured
.split("").map(x
=> parseInt(x
, 10));
138 const pieces
= ['p', 'r', 'n', 'b', 'q', 'k'];
140 w: Array
.toObject(pieces
, allCapts
.slice(0, 6)),
141 b: Array
.toObject(pieces
, allCapts
.slice(6, 12))
143 this.reserve
= { w: {}, b: {} }; //to be replaced by this.captured
147 // For Toadette bonus
148 getDropMovesFrom([c
, p
]) {
149 if (this.reserve
[c
][p
] == 0)
152 const start
= (c
== 'w' && p
== 'p' ? 1 : 0);
153 const end
= (color
== 'b' && p
== 'p' ? 7 : 8);
154 for (let i
= start
; i
< end
; i
++) {
155 for (let j
= 0; j
< this.size
.y
; j
++) {
156 const pieceIJ
= this.getPiece(i
, j
);
158 this.board
[i
][j
] == "" ||
159 this.getColor(i
, j
) == 'a' ||
160 pieceIJ
== V
.INVISIBLE_QUEEN
165 appear: [new PiPo({x: i
, y: j
, c: c
, p: p
})],
168 // A drop move may remove a bonus (or hidden queen!)
169 if (this.board
[i
][j
] != "")
170 m
.vanish
.push(new PiPo({x: i
, y: j
, c: 'a', p: pieceIJ
}));
187 // TODO: rethink from here:
191 // queen invisible move, king shell: special functions
193 // prevent pawns from capturing invisible queen (post)
196 //events : playPlusVisual after mouse up, playReceived (include animation) on opp move
197 // ==> if move.cont (banana...) self re-call playPlusVisual (rec ?)
199 // Initial call: effects resolved after playing
200 getPotentialMovesFrom([x
, y
]) {
202 switch (this.getPiece(x
, y
)) {
204 moves
= this.getPawnMovesFrom([x
, y
]); //apply promotions
207 moves
= this.getQueenMovesFrom([x
, y
]);
210 moves
= this.getKingMoves([x
, y
]);
213 moves
= super.getPotentialMovesFrom([x
, y
]);
220 tryMoveFollowup(move) {
221 if (this.getColor(move.end
.x
, move.end
.y
) == 'a') {
222 // effect, or bonus/malus
223 const endType
= this.getPiece(m
.end
.x
, m
.end
.y
);
224 if (endType
== V
.EGG
)
225 this.applyRandomBonus(m
);
227 this.moveStack
.push(m
);
233 // aller dans direction, saut par dessus pièce adverse
234 // ou amie (tjours), new step si roi caval pion
240 const finalPieces
= V
.PawnSpecs
.promotions
;
241 const color
= this.turn
;
242 const lastRank
= (color
== "w" ? 0 : 7);
246 m
.appear
.length
> 0 &&
247 ['p', 's'].includes(m
.appear
[0].p
) &&
248 m
.appear
[0].x
== lastRank
250 for (let i
= 1; i
< finalPieces
.length
; i
++) {
251 const piece
= finalPieces
[i
];
252 let otherM
= JSON
.parse(JSON
.stringify(m
));
254 m
.appear
[0].p
== V
.PAWN
256 : V
.IMMOBILIZE_CODE
[finalPieces
[i
]];
259 // Finally alter m itself:
261 m
.appear
[0].p
== V
.PAWN
263 : V
.IMMOBILIZE_CODE
[finalPieces
[0]];
266 Array
.prototype.push
.apply(moves
, pMoves
);
270 const L
= this.effects
.length
;
271 switch (this.effects
[L
-1]) {
273 // Exchange position with any visible piece,
274 // except pawns if arriving on last rank.
275 const lastRank
= { 'w': 0, 'b': 7 };
276 const color
= this.turn
;
277 const allowLastRank
= (this.getPiece(x
, y
) != V
.PAWN
);
278 for (let i
=0; i
<8; i
++) {
279 for (let j
=0; j
<8; j
++) {
280 const colIJ
= this.getColor(i
, j
);
281 const pieceIJ
= this.getPiece(i
, j
);
283 (i
!= x
|| j
!= y
) &&
284 this.board
[i
][j
] != V
.EMPTY
&&
285 pieceIJ
!= V
.INVISIBLE_QUEEN
&&
289 (pieceIJ
!= V
.PAWN
|| x
!= lastRank
[colIJ
]) &&
290 (allowLastRank
|| i
!= lastRank
[color
])
292 const movedUnit
= new PiPo({
296 p: this.getPiece(i
, j
)
298 let mMove
= this.getBasicMove({ x: x
, y: y
}, [i
, j
]);
299 mMove
.appear
.push(movedUnit
);
307 // Resurrect a captured piece
308 if (x
>= V
.size
.x
) moves
= this.getReserveMoves([x
, y
]);
311 // Play again with any piece
312 moves
= super.getPotentialMovesFrom([x
, y
]);
319 // Helper for getBasicMove(): banana/bomb effect
320 getRandomSquare([x
, y
], steps
) {
321 const validSteps
= steps
.filter(s
=> this.onBoard(x
+ s
[0], y
+ s
[1]));
322 const step
= validSteps
[Random
.randInt(validSteps
.length
)];
323 return [x
+ step
[0], y
+ step
[1]];
326 // Apply mushroom, bomb or banana effect (hidden to the player).
327 // Determine egg effect, too, and apply its first part if possible.
328 getBasicMove_aux(psq1
, sq2
, tr
, initMove
) {
329 const [x1
, y1
] = [psq1
.x
, psq1
.y
];
330 const color1
= this.turn
;
331 const piece1
= (!!tr
? tr
.p : (psq1
.p
|| this.getPiece(x1
, y1
)));
332 const oppCol
= V
.GetOppCol(color1
);
338 // banana or bomb defines next square, or the move ends there
347 if (this.board
[x1
][y1
] != V
.EMPTY
) {
348 const initP1
= this.getPiece(x1
, y1
);
353 c: this.getColor(x1
, y1
),
357 if ([V
.BANANA
, V
.BOMB
].includes(initP1
)) {
358 const steps
= V
.steps
[initP1
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
359 move.next
= this.getRandomSquare([x1
, y1
], steps
);
362 move.end
= { x: x1
, y: y1
};
365 const [x2
, y2
] = [sq2
[0], sq2
[1]];
366 // The move starts normally, on board:
367 let move = super.getBasicMove([x1
, y1
], [x2
, y2
], tr
);
368 if (!!tr
) move.promoteInto
= tr
.c
+ tr
.p
; //in case of (chomped...)
369 const L
= this.effects
.length
;
371 [V
.PAWN
, V
.KNIGHT
].includes(piece1
) &&
373 (this.subTurn
== 1 || this.effects
[L
-1] == "daisy")
377 const twoSquaresMove
= (Math
.abs(x2
- x1
) == 2);
378 const mushroomX
= x1
+ (twoSquaresMove
? (x2
- x1
) / 2 : 0);
387 if (this.getColor(mushroomX
, y1
) == 'a') {
393 p: this.getPiece(mushroomX
, y1
)
400 const deltaX
= Math
.abs(x2
- x1
);
401 const deltaY
= Math
.abs(y2
- y1
);
403 x1
+ (deltaX
== 2 ? (x2
- x1
) / 2 : 0),
404 y1
+ (deltaY
== 2 ? (y2
- y1
) / 2 : 0)
407 this.board
[eggSquare
[0]][eggSquare
[1]] != V
.EMPTY
&&
408 this.getColor(eggSquare
[0], eggSquare
[1]) != 'a'
421 if (this.getColor(eggSquare
[0], eggSquare
[1]) == 'a') {
427 p: this.getPiece(eggSquare
[0], eggSquare
[1])
435 // For (wa)luigi effect:
436 const changePieceColor
= (color
) => {
438 const oppLastRank
= (color
== 'w' ? 7 : 0);
439 for (let i
=0; i
<8; i
++) {
440 for (let j
=0; j
<8; j
++) {
441 const piece
= this.getPiece(i
, j
);
443 (i
!= move.vanish
[0].x
|| j
!= move.vanish
[0].y
) &&
444 this.board
[i
][j
] != V
.EMPTY
&&
445 piece
!= V
.INVISIBLE_QUEEN
&&
446 this.getColor(i
, j
) == color
448 if (piece
!= V
.KING
&& (piece
!= V
.PAWN
|| i
!= oppLastRank
))
449 pieces
.push({ x: i
, y: j
, p: piece
});
453 // Special case of the current piece (still at its initial position)
455 pieces
.push({ x: move.appear
[0].x
, y: move.appear
[0].y
, p: piece1
});
456 const cp
= pieces
[randInt(pieces
.length
)];
457 if (move.appear
[0].x
!= cp
.x
|| move.appear
[0].y
!= cp
.y
) {
467 else move.appear
.shift();
472 c: V
.GetOppCol(color
),
477 const applyEggEffect
= () => {
478 if (this.subTurn
== 2)
479 // No egg effects at subTurn 2
481 // 1) Determine the effect (some may be impossible)
482 let effects
= ["kingboo", "koopa", "chomp", "bowser", "daisy"];
483 if (Object
.values(this.captured
[color1
]).some(c
=> c
>= 1))
484 effects
.push("toadette");
485 const lastRank
= { 'w': 0, 'b': 7 };
487 this.board
.some((b
,i
) =>
492 (cell
[1] != V
.PAWN
|| i
!= lastRank
[color1
])
497 effects
.push("luigi");
502 (piece1
!= V
.PAWN
|| move.appear
[0].x
!= lastRank
[oppCol
])
504 this.board
.some((b
,i
) =>
509 (cell
[1] != V
.PAWN
|| i
!= lastRank
[oppCol
])
514 effects
.push("waluigi");
516 const effect
= effects
[randInt(effects
.length
)];
517 move.end
.effect
= effect
;
518 // 2) Apply it if possible
519 if (!(["kingboo", "toadette", "daisy"].includes(effect
))) {
523 // Maybe egg effect was applied after others,
524 // so just shift vanish array:
531 move.appear
[0].p
= V
.IMMOBILIZE_CODE
[piece1
];
534 changePieceColor(oppCol
);
537 changePieceColor(color1
);
542 const applyMushroomEffect
= () => {
543 if ([V
.PAWN
, V
.KING
, V
.KNIGHT
].includes(piece1
)) {
544 // Just make another similar step, if possible (non-capturing)
546 move.appear
[0].x
+ (x2
- x1
),
547 move.appear
[0].y
+ (y2
- y1
)
552 this.board
[i
][j
] == V
.EMPTY
||
553 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
||
554 this.getColor(i
, j
) == 'a'
557 move.appear
[0].x
= i
;
558 move.appear
[0].y
= j
;
559 if (this.board
[i
][j
] != V
.EMPTY
) {
560 const object
= this.getPiece(i
, j
);
561 const color
= this.getColor(i
, j
);
573 const steps
= V
.steps
[object
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
574 move.next
= this.getRandomSquare([i
, j
], steps
);
580 applyMushroomEffect();
587 // Queen, bishop or rook:
589 (x2
- x1
) / Math
.abs(x2
- x1
) || 0,
590 (y2
- y1
) / Math
.abs(y2
- y1
) || 0
592 const next
= [move.appear
[0].x
+ step
[0], move.appear
[0].y
+ step
[1]];
594 V
.OnBoard(next
[0], next
[1]) &&
595 this.board
[next
[0]][next
[1]] != V
.EMPTY
&&
596 this.getPiece(next
[0], next
[1]) != V
.INVISIBLE_QUEEN
&&
597 this.getColor(next
[0], next
[1]) != 'a'
599 const afterNext
= [next
[0] + step
[0], next
[1] + step
[1]];
600 if (V
.OnBoard(afterNext
[0], afterNext
[1])) {
601 const afterColor
= this.getColor(afterNext
[0], afterNext
[1]);
603 this.board
[afterNext
[0]][afterNext
[1]] == V
.EMPTY
||
606 move.appear
[0].x
= afterNext
[0];
607 move.appear
[0].y
= afterNext
[1];
608 if (this.board
[afterNext
[0]][afterNext
[1]] != V
.EMPTY
) {
609 // object = banana, bomb, mushroom or egg
610 const object
= this.getPiece(afterNext
[0], afterNext
[1]);
623 V
.steps
[object
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
624 move.next
= this.getRandomSquare(
625 [afterNext
[0], afterNext
[1]], steps
);
631 applyMushroomEffect();
640 const color2
= this.getColor(x2
, y2
);
641 const piece2
= this.getPiece(x2
, y2
);
646 const steps
= V
.steps
[piece2
== V
.BANANA
? V
.ROOK : V
.BISHOP
];
647 move.next
= this.getRandomSquare([x2
, y2
], steps
);
650 applyMushroomEffect();
653 if (this.subTurn
== 1)
654 // No egg effect at subTurn 2
662 move.appear
.length
> 0 &&
663 [V
.ROOK
, V
.BISHOP
].includes(piece1
)
665 const finalSquare
= [move.appear
[0].x
, move.appear
[0].y
];
668 this.getColor(finalSquare
[0], finalSquare
[1]) != 'a' ||
669 this.getPiece(finalSquare
[0], finalSquare
[1]) != V
.EGG
672 V
.steps
[piece1
== V
.ROOK
? V
.BISHOP : V
.ROOK
].filter(s
=> {
673 const [i
, j
] = [finalSquare
[0] + s
[0], finalSquare
[1] + s
[1]];
676 // NOTE: do not place a bomb or banana on the invisible queen!
677 (this.board
[i
][j
] == V
.EMPTY
|| this.getColor(i
, j
) == 'a')
680 if (validSteps
.length
>= 1) {
681 const randIdx
= randInt(validSteps
.length
);
683 finalSquare
[0] + validSteps
[randIdx
][0],
684 finalSquare
[1] + validSteps
[randIdx
][1]
691 p: (piece1
== V
.ROOK
? V
.BANANA : V
.BOMB
)
694 if (this.board
[x
][y
] != V
.EMPTY
) {
696 new PiPo({ x: x
, y: y
, c: 'a', p: this.getPiece(x
, y
) }));
704 getBasicMove(psq1
, sq2
, tr
) {
706 if (Array
.isArray(psq1
)) psq1
= { x: psq1
[0], y: psq1
[1] };
707 let m
= this.getBasicMove_aux(psq1
, sq2
, tr
, "initMove");
709 // Last move ended on bomb or banana, direction change
710 V
.PlayOnBoard(this.board
, m
);
712 m
= this.getBasicMove_aux(
713 { x: m
.appear
[0].x
, y: m
.appear
[0].y
}, m
.next
);
715 for (let i
=moves
.length
-1; i
>=0; i
--) V
.UndoOnBoard(this.board
, moves
[i
]);
717 // Now merge moves into one
719 // start is wrong for Toadette moves --> it's fixed later
720 move.start
= { x: psq1
.x
, y: psq1
.y
};
721 move.end
= !!sq2
? { x: sq2
[0], y: sq2
[1] } : { x: psq1
.x
, y: psq1
.y
};
722 if (!!tr
) move.promoteInto
= moves
[0].promoteInto
;
723 let lm
= moves
[moves
.length
-1];
724 if (this.subTurn
== 1 && !!lm
.end
.effect
)
725 move.end
.effect
= lm
.end
.effect
;
726 if (moves
.length
== 1) {
727 move.appear
= moves
[0].appear
;
728 move.vanish
= moves
[0].vanish
;
731 // Keep first vanish and last appear (if any)
732 move.appear
= lm
.appear
;
733 move.vanish
= moves
[0].vanish
;
735 move.vanish
.length
>= 1 &&
736 move.appear
.length
>= 1 &&
737 move.vanish
[0].x
== move.appear
[0].x
&&
738 move.vanish
[0].y
== move.appear
[0].y
740 // Loopback on initial square:
744 for (let i
=1; i
< moves
.length
- 1; i
++) {
745 for (let v
of moves
[i
].vanish
) {
746 // Only vanishing objects, not appearing at init move
750 moves
[0].appear
.length
== 1 ||
751 moves
[0].appear
[1].x
!= v
.x
||
752 moves
[0].appear
[1].y
!= v
.y
759 // Final vanish is our piece, but others might be relevant
760 // (for some egg bonuses at least).
761 for (let i
=1; i
< lm
.vanish
.length
; i
++) {
763 lm
.vanish
[i
].c
!= 'a' ||
764 moves
[0].appear
.length
== 1 ||
765 moves
[0].appear
[1].x
!= lm
.vanish
[i
].x
||
766 moves
[0].appear
[1].y
!= lm
.vanish
[i
].y
768 move.vanish
.push(lm
.vanish
[i
]);
775 getPotentialPawnMoves([x
, y
]) {
776 const color
= this.turn
;
777 const oppCol
= V
.GetOppCol(color
);
778 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
779 const shiftX
= V
.PawnSpecs
.directions
[color
];
780 const firstRank
= (color
== "w" ? sizeX
- 1 : 0);
783 this.board
[x
+ shiftX
][y
] == V
.EMPTY
||
784 this.getColor(x
+ shiftX
, y
) == 'a' ||
785 this.getPiece(x
+ shiftX
, y
) == V
.INVISIBLE_QUEEN
787 this.addPawnMoves([x
, y
], [x
+ shiftX
, y
], moves
);
789 [firstRank
, firstRank
+ shiftX
].includes(x
) &&
791 this.board
[x
+ 2 * shiftX
][y
] == V
.EMPTY
||
792 this.getColor(x
+ 2 * shiftX
, y
) == 'a' ||
793 this.getPiece(x
+ 2 * shiftX
, y
) == V
.INVISIBLE_QUEEN
796 moves
.push(this.getBasicMove({ x: x
, y: y
}, [x
+ 2 * shiftX
, y
]));
799 for (let shiftY
of [-1, 1]) {
802 y
+ shiftY
< sizeY
&&
803 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
804 // Pawns cannot capture invisible queen this way!
805 this.getPiece(x
+ shiftX
, y
+ shiftY
) != V
.INVISIBLE_QUEEN
&&
806 ['a', oppCol
].includes(this.getColor(x
+ shiftX
, y
+ shiftY
))
808 this.addPawnMoves([x
, y
], [x
+ shiftX
, y
+ shiftY
], moves
);
814 getPotentialQueenMoves(sq
) {
815 const normalMoves
= super.getPotentialQueenMoves(sq
);
816 // If flag allows it, add 'invisible movements'
817 let invisibleMoves
= [];
818 if (this.powerFlags
[this.turn
][V
.QUEEN
]) {
819 normalMoves
.forEach(m
=> {
821 m
.appear
.length
== 1 &&
822 m
.vanish
.length
== 1 &&
823 // Only simple non-capturing moves:
826 let im
= JSON
.parse(JSON
.stringify(m
));
827 im
.appear
[0].p
= V
.INVISIBLE_QUEEN
;
828 im
.end
.noHighlight
= true;
829 invisibleMoves
.push(im
);
833 return normalMoves
.concat(invisibleMoves
);
836 getPotentialKingMoves([x
, y
]) {
837 let moves
= super.getPotentialKingMoves([x
, y
]);
838 const color
= this.turn
;
839 // If flag allows it, add 'remote shell captures'
840 if (this.powerFlags
[this.turn
][V
.KING
]) {
841 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]).forEach(step
=> {
842 let [i
, j
] = [x
+ step
[0], y
+ step
[1]];
846 this.board
[i
][j
] == V
.EMPTY
||
847 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
||
849 this.getColor(i
, j
) == 'a' &&
850 [V
.EGG
, V
.MUSHROOM
].includes(this.getPiece(i
, j
))
857 if (V
.OnBoard(i
, j
)) {
858 const colIJ
= this.getColor(i
, j
);
859 if (colIJ
!= color
) {
860 // May just destroy a bomb or banana:
863 start: { x: x
, y: y
},
868 x: i
, y: j
, c: colIJ
, p: this.getPiece(i
, j
)
880 getSlideNJumpMoves([x
, y
], steps
, oneStep
) {
882 outerLoop: for (let step
of steps
) {
888 this.board
[i
][j
] == V
.EMPTY
||
889 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
||
891 this.getColor(i
, j
) == 'a' &&
892 [V
.EGG
, V
.MUSHROOM
].includes(this.getPiece(i
, j
))
896 moves
.push(this.getBasicMove({ x: x
, y: y
}, [i
, j
]));
897 if (oneStep
) continue outerLoop
;
901 if (V
.OnBoard(i
, j
) && this.canTake([x
, y
], [i
, j
]))
902 moves
.push(this.getBasicMove({ x: x
, y: y
}, [i
, j
]));
907 getAllPotentialMoves() {
908 if (this.subTurn
== 1) return super.getAllPotentialMoves();
910 const color
= this.turn
;
911 const L
= this.effects
.length
;
912 switch (this.effects
[L
-1]) {
915 for (let i
=0; i
<8; i
++) {
916 for (let j
=0; j
<8; j
++) {
917 const colIJ
= this.getColor(i
, j
);
918 const pieceIJ
= this.getPiece(i
, j
);
921 this.board
[i
][j
] != V
.EMPTY
&&
923 pieceIJ
!= V
.INVISIBLE_QUEEN
925 allPieces
.push({ x: i
, y: j
, c: colIJ
, p: pieceIJ
});
929 for (let x
=0; x
<8; x
++) {
930 for (let y
=0; y
<8; y
++) {
931 if (this.getColor(i
, j
) == color
) {
932 // Add exchange with something
933 allPieces
.forEach(pp
=> {
934 if (pp
.x
!= i
|| pp
.y
!= j
) {
935 const movedUnit
= new PiPo({
941 let mMove
= this.getBasicMove({ x: x
, y: y
}, [pp
.x
, pp
.y
]);
942 mMove
.appear
.push(movedUnit
);
952 const x
= V
.size
.x
+ (this.turn
== 'w' ? 0 : 1);
953 for (let y
= 0; y
< 8; y
++)
954 Array
.prototype.push
.apply(moves
, this.getReserveMoves([x
, y
]));
958 moves
= super.getAllPotentialMoves();
973 /// if any of my pieces was immobilized, it's not anymore.
974 //if play set a piece immobilized, then mark it
976 if (move.effect
== "toadette")
977 this.reserve
= this.captured
;
979 this.reserve
= { w: {}, b: {} };;
980 const color
= this.turn
;
982 move.vanish
.length
== 2 &&
983 move.vanish
[1].c
!= 'a' &&
984 move.appear
.length
== 1 //avoid king Boo!
986 // Capture: update this.captured
987 let capturedPiece
= move.vanish
[1].p
;
988 if (capturedPiece
== V
.INVISIBLE_QUEEN
)
989 capturedPiece
= V
.QUEEN
;
990 else if (Object
.keys(V
.IMMOBILIZE_DECODE
).includes(capturedPiece
))
991 capturedPiece
= V
.IMMOBILIZE_DECODE
[capturedPiece
];
992 this.captured
[move.vanish
[1].c
][capturedPiece
]++;
994 else if (move.vanish
.length
== 0) {
995 if (move.appear
.length
== 0 || move.appear
[0].c
== 'a') return;
996 // A piece is back on board
997 this.captured
[move.appear
[0].c
][move.appear
[0].p
]--;
999 if (move.appear
.length
== 0) {
1000 // Three cases: king "shell capture", Chomp or Koopa
1001 if (this.getPiece(move.start
.x
, move.start
.y
) == V
.KING
)
1002 // King remote capture:
1003 this.powerFlags
[color
][V
.KING
] = false;
1004 else if (move.end
.effect
== "chomp")
1005 this.captured
[color
][move.vanish
[0].p
]++;
1007 else if (move.appear
[0].p
== V
.INVISIBLE_QUEEN
)
1008 this.powerFlags
[move.appear
[0].c
][V
.QUEEN
] = false;
1009 if (this.subTurn
== 2) return;
1011 move.turn
[1] == 1 &&
1012 move.appear
.length
== 0 ||
1013 !(Object
.keys(V
.IMMOBILIZE_DECODE
).includes(move.appear
[0].p
))
1015 // Look for an immobilized piece of my color: it can now move
1016 for (let i
=0; i
<8; i
++) {
1017 for (let j
=0; j
<8; j
++) {
1018 if (this.board
[i
][j
] != V
.EMPTY
) {
1019 const piece
= this.getPiece(i
, j
);
1021 this.getColor(i
, j
) == color
&&
1022 Object
.keys(V
.IMMOBILIZE_DECODE
).includes(piece
)
1024 this.board
[i
][j
] = color
+ V
.IMMOBILIZE_DECODE
[piece
];
1025 move.wasImmobilized
= [i
, j
];
1031 // Also make opponent invisible queen visible again, if any
1032 const oppCol
= V
.GetOppCol(color
);
1033 for (let i
=0; i
<8; i
++) {
1034 for (let j
=0; j
<8; j
++) {
1036 this.board
[i
][j
] != V
.EMPTY
&&
1037 this.getColor(i
, j
) == oppCol
&&
1038 this.getPiece(i
, j
) == V
.INVISIBLE_QUEEN
1040 this.board
[i
][j
] = oppCol
+ V
.QUEEN
;
1041 move.wasInvisible
= [i
, j
];
1049 this.playOnBoard(move);
1050 if (["kingboo", "toadette", "daisy"].includes(move.effect
)) {
1051 this.effect
= move.effect
;
1055 this.turn
= C
.GetOppCol(this.turn
);
1061 filterValid(moves
) {
1065 // TODO + display bonus messages
1066 // + animation + multi-moves for bananas/bombs/mushrooms