- // if subturn == 1, normal situation, allow moves except walking back on sentryPath,
- // if last element isn't null in sentryPath array
- // if subTurn == 2, allow only the end of the path (occupied by a piece) to move
- //
- // TODO: special pass move: take jailer with king, only if king immobilized
- // Move(appear:[], vanish:[], start == king and end = jailer (for animation))
- //
- // TODO: post-processing if sentryPath forbid some moves.
- // + add all lancer possible orientations
- // (except if just after a push: allow all movements from init square then)
- // Test if last sentryPath ends at our position: if yes, OK
+ if (this.subTurn == 1) {
+ if (!!this.isImmobilized([x, y])) return [];
+ return this.getPotentialMovesFrom_aux([x, y]);
+ }
+ // subTurn == 2: only the piece pushed by the sentry is allowed to move,
+ // as if the sentry didn't exist
+ if (x != this.sentryPos.x && y != this.sentryPos.y) return [];
+ return this.getPotentialMovesFrom_aux([x,y]);
+ }
+
+ getAllValidMoves() {
+ let moves = super.getAllValidMoves().filter(m => {
+ // Remove jailer captures
+ return m.vanish[0].p != V.JAILER || m.vanish.length == 1;
+ });
+ const L = this.sentryPush.length;
+ if (!!this.sentryPush[L-1] && this.subTurn == 1) {
+ // Delete moves walking back on sentry push path
+ moves = moves.filter(m => {
+ if (
+ m.vanish[0].p != V.PAWN &&
+ this.sentryPush[L-1].some(sq => sq.x == m.end.x && sq.y == m.end.y)
+ ) {
+ return false;
+ }
+ return true;
+ });
+ }
+ return moves;
+ }
+
+ filterValid(moves) {
+ // Disable check tests when subTurn == 2, because the move isn't finished
+ if (this.subTurn == 2) return moves;
+ return super.filterValid(moves);
+ }
+
+ getPotentialLancerMoves([x, y]) {
+ // TODO: add all lancer possible orientations same as pawn promotions,
+ // except if just after a push: allow all movements from init square then
+ return [];
+ }
+
+ getPotentialSentryMoves([x, y]) {
+ // The sentry moves a priori like a bishop:
+ let moves = super.getPotentialBishopMoves([x, y]);
+ // ...but captures are replaced by special move
+ // "appear = [], vanish = init square" to let the pushed piece move then.
+ // TODO
+ }
+
+ getPotentialJailerMoves([x, y]) {
+ // Captures are removed afterward:
+ return super.getPotentialRookMoves([x, y]);
+ }
+
+ getPotentialKingMoves([x, y]) {
+ let moves = super.getPotentialKingMoves([x, y]);
+ // Augment with pass move is the king is immobilized:
+ const jsq = this.isImmobilized([x, y]);
+ if (!!jsq) {
+ moves.push(
+ new Move({
+ appear: [],
+ vanish: [],
+ start: { x: x, y: y },
+ end: { x: jsq[0], y: jsq[1] }
+ })
+ );
+ }
+ return moves;