+ filterValid(moves) {
+ if (moves.length == 0) return [];
+ const color = this.turn;
+ const lastRanks = (color == 'w' ? [0, 1] : [8, 7]);
+ return moves.filter(m => {
+ if (
+ (m.appear[0].p == V.KNIGHT && lastRanks.includes(m.end.x)) ||
+ ([V.PAWN, V.LANCE].includes(m.appear[0].p) && lastRanks[0] == m.end.x)
+ ) {
+ // Forbid moves resulting in a blocked piece
+ return false;
+ }
+ this.play(m);
+ const res = !this.underCheck(color);
+ this.undo(m);
+ return res;
+ });
+ }
+