}
canTake([x1, y1], [x2, y2]) {
- // Capture enemy or pass ball to friendly pieces
+ if (this.getColor(x1, y1) !== this.getColor(x2, y2)) {
+ // The piece holding the ball cannot capture:
+ return (
+ !(Object.keys(V.HAS_BALL_DECODE)
+ .includes(this.board[x1][y1].charAt(1)))
+ );
+ }
+ // Pass: possible only if one of the friendly pieces has the ball
return (
- this.getColor(x1, y1) !== this.getColor(x2, y2) ||
- Object.keys(V.HAS_BALL_DECODE).includes(this.board[x1][y1].charAt(1))
+ Object.keys(V.HAS_BALL_DECODE).includes(this.board[x1][y1].charAt(1)) ||
+ Object.keys(V.HAS_BALL_DECODE).includes(this.board[x2][y2].charAt(1))
);
}
break;
}
- // Get random squares for every piece, totally freely
+ // Get random squares for every piece, with bishops and phoenixes
+ // on different colors:
let positions = shuffle(ArrayFun.range(9));
- const composition = ['b', 'b', 'r', 'r', 'n', 'n', 'h', 'h', 'q'];
- const rem2 = positions[0] % 2;
+ const composition = ['b', 'b', 'h', 'h', 'n', 'n', 'r', 'r', 'q'];
+ let rem2 = positions[0] % 2;
if (rem2 == positions[1] % 2) {
// Fix bishops (on different colors)
- for (let i=2; i<9; i++) {
+ for (let i=4; i<9; i++) {
if (positions[i] % 2 != rem2)
[positions[1], positions[i]] = [positions[i], positions[1]];
}
}
+ rem2 = positions[2] % 2;
+ if (rem2 == positions[3] % 2) {
+ // Fix phoenixes too:
+ for (let i=4; i<9; i++) {
+ if (positions[i] % 2 != rem2)
+ [positions[3], positions[i]] = [positions[i], positions[3]];
+ }
+ }
for (let i = 0; i < 9; i++) pieces[c][positions[i]] = composition[i];
}
return (
);
}
- // Post-processing: maybe the ball was taken, or a piece + ball
+ // Post-processing: maybe the ball was taken, or a piece + ball,
+ // or maybe a pass (ball <--> piece)
if (mv.vanish.length == 2) {
if (
// Take the ball?
mv.vanish[1].c == 'a' ||
- // Capture a ball-holding piece?
+ // Capture a ball-holding piece? If friendly one, then adjust
Object.keys(V.HAS_BALL_DECODE).includes(mv.vanish[1].p)
) {
mv.appear[0].p = V.HAS_BALL_CODE[mv.appear[0].p];
+ if (mv.vanish[1].c == mv.vanish[0].c) {
+ // "Capturing" self => pass
+ mv.appear[0].x = mv.start.x;
+ mv.appear[0].y = mv.start.y;
+ mv.appear.push(
+ new PiPo({
+ x: mv.end.x,
+ y: mv.end.y,
+ p: V.HAS_BALL_DECODE[mv.vanish[1].p],
+ c: mv.vanish[0].c
+ })
+ );
+ }
} else if (mv.vanish[1].c == mv.vanish[0].c) {
// Pass the ball: the passing unit does not disappear
mv.appear.push(JSON.parse(JSON.stringify(mv.vanish[0])));
return super.getPotentialMovesFrom([x, y]);
}
- // "Sliders": at most 2 steps
+ // "Sliders": at most 3 steps
getSlideNJumpMoves([x, y], steps, oneStep) {
let moves = [];
outerLoop: for (let step of steps) {
let stepCount = 1;
while (V.OnBoard(i, j) && this.board[i][j] == V.EMPTY) {
moves.push(this.getBasicMove([x, y], [i, j]));
- if (oneStep || stepCount == 2) continue outerLoop;
+ if (oneStep || stepCount == 3) continue outerLoop;
i += step[0];
j += step[1];
stepCount++;