- case V.MUSHROOM:
- // aller dans direction, saut par dessus pièce adverse
- // ou amie (tjours), new step si roi caval pion
+ case V.MUSHROOM: {
+ let step = [move.end.x - move.start.x, move.end.y - move.start.y];
+ if ([0, 1].some(i => step[i] >= 2 && step[1-i] != 1)) {
+ // Slider, multi-squares: normalize step
+ for (let j of [0, 1])
+ step[j] = step[j] / Math.abs(step[j]) || 0;
+ }
+ const nextSquare = [move.end.x + step[0], move.end.y + step[1]];
+ if (this.onBoard(nextSquare[0], nextSquare[1])) {
+ if (
+ this.board[nextSquare[0]][nextSquare[1]] != "" &&
+ this.getColor(nextSquare[0], nextSquare[1]) != 'a'
+ ) {
+ // (try to) jump
+ const afterSquare =
+ [nextSquare[0] + step[0], nextSquare[1] + step[1]];
+ if (
+ this.onBoard(afterSquare[0], afterSquare[1]) &&
+ this.getColor(afterSquare[0], afterSquare[1]) != this.turn
+ ) {
+ cb(this.getBasicMove([move.end.x, move.end.y], afterSquare));
+ }
+ }
+ else if (!['b', 'r', 'q'].includes(move.vanish[0].p))
+ // Take another step forward if not slider move
+ cb(this.getBasicMove([move.end.x, move.end.y], nextSquare));
+ }