1 import { ChessRulesi
, PiPo
} from "@/base_rules";
3 export class KoopaRules
extends ChessRules
{
4 static get HasEnpassant() {
8 // Between stun time and stun + 1 move
9 static get STUNNED_1() {
10 return ['s', 'u', 'o', 'c', 't', 'l'];
13 // Between stun + 1 move and stun + 2 moves
14 static get STUNNED_2() {
15 return ['v', 'x', 'a', 'd', 'w', 'm'];
19 return ChessRules
.PIECES
.concat(V
.STUNNED_1
).concat(V
.STUNNED_2
);
22 getNormalizedStep(step
) {
23 const [deltaX
, deltaY
] = [Math
.abs(step
[0]), Math
.abs(step
[1])];
24 if (deltaX
== 0 || deltaY
== 0 || deltaX
== deltaY
)
25 return [step
[0] / deltaX
|| 0, step
[1] / deltaY
|| 0];
27 const divisor
= Math
.min(deltaX
, deltaY
)
28 return [step
[0] / divisor
, step
[1] / divisor
];
31 getPotentialMovesFrom([x
, y
]) {
32 let moves
= super.getPotentialMovesFrom([x
, y
]);
33 // Complete moves: stuns & kicks
34 const stun
= V
.STUNNED_1
.concat(V
.STUNNED_2
);
36 if (m
.vanish
.length
== 2 && m
.appear
.length
== 1) {
38 this.getNormalizedStep([m
.end
.x
- m
.start
.x
, m
.end
.y
- m
.start
.y
]);
39 // "Capture" something: is target stunned?
40 if (stun
.includes(m
.vanish
[1].p
)) {
41 // Kick it: continue movement in the same direction,
42 // destroying all on its path.
43 let [i
, j
] = [m
.end
.x
+ step
[0], m
.end
.y
+ step
[1]];
44 while (V
.OnBoard(i
, j
)) {
45 if (this.board
[i
][j
] != V
.EMPTY
) {
50 c: this.getColor(i
, j
),
51 p: this.getPiece(i
, j
)
60 // The piece is now stunned
61 m
.appear
.push(m
.vanish
.pop());
62 const pIdx
= ChessRules
.PIECES
.findIndex(p
=> p
== m
.appear
[1].p
);
63 m
.appear
[1].p
= V
.STUNNED_1
[pIdx
];
64 // And the capturer continue in the same direction until an empty
65 // square or the edge of the board, maybe stunning other pieces.
66 let [i
, j
] = [m
.end
.x
+ step
[0], m
.end
.y
+ step
[1]];
67 while (V
.OnBoard(i
, j
) && this.board
[i
][j
] != V
.EMPTY
) {
68 const colIJ
= this.getColor(i
, j
);
69 const pieceIJ
= this.getPiece(i
, j
);
78 const pIdx
= ChessRules
.PIECES
.findIndex(p
=> p
== pieceIJ
);
90 if (V
.OnBoard(i
, j
)) {
93 // Is it a pawn on last rank?
105 static GenRandInitFen(randomness
) {
107 return ChessRules
.GenRandInitFen(randomness
).slice(0, -2);
111 // Forbid kicking own king out
112 const color
= this.turn
;
113 return moves
.filter(m
=> {
114 return m
.vanish
.every(v
=> v
.c
!= color
|| !(['l','m'].includes(v
.p
)));
123 if (this.kingPos
['w'][0] < 0) return "0-1";
124 if (this.kingPos
['b'][0] < 0) return "1-0";
125 if (!this.atLeastOneMove()) return "1/2";
130 // TODO: toutes les pièces "stunned" by me (turn) avancent d'un niveau
132 move.wasStunned
= array
of stunned stage
2 pieces (just back to normal then
)