1 import ChessRules
from "/base_rules.js";
2 import {ArrayFun
} from "/utils/array.js";
4 export default class AliceRules
extends ChessRules
{
8 select: C
.Options
.select
,
9 input: C
.Options
.input
,
22 // To the other side of the mirror and back...
23 static get ALICE_PIECES() {
33 static get ALICE_CODES() {
46 p
= this.getPiece(x
, y
);
47 return ['k', 'l'].includes(p
);
52 's': {"class": "alice-pawn", moveas: 'p'},
53 'u': {"class": "alice-rook", moveas: 'r'},
54 'o': {"class": "alice-knight", moveas: 'n'},
55 'c': {"class": "alice-bishop", moveas: 'b'},
56 't': {"class": "alice-queen", moveas: 'q'},
57 'l': {"class": "alice-king", moveas: 'k'}
59 return Object
.assign(alices
, super.pieces(color
, x
, y
));
62 fromSameWorld(p1
, p2
) {
64 (V
.ALICE_PIECES
[p1
] && V
.ALICE_PIECES
[p2
]) ||
65 (V
.ALICE_CODES
[p1
] && V
.ALICE_CODES
[p2
])
69 // Step of p over i,j ?
70 canStepOver(i
, j
, p
) {
72 this.board
[i
][j
] == "" || !this.fromSameWorld(this.getPiece(i
, j
), p
));
75 getPotentialMovesFrom([x
, y
]) {
76 return super.getPotentialMovesFrom([x
, y
]).filter(m
=> {
77 // Remove moves landing on occupied square on other board
79 this.board
[m
.end
.x
][m
.end
.y
] == "" ||
80 this.fromSameWorld(m
.vanish
[0].p
, m
.vanish
[1].p
)
83 // Apply Alice rule: go to the other side of the mirror
84 if (Object
.keys(V
.ALICE_CODES
).includes(m
.vanish
[0].p
))
86 m
.appear
.forEach(a
=> a
.p
= V
.ALICE_CODES
[a
.p
])
89 m
.appear
.forEach(a
=> a
.p
= V
.ALICE_PIECES
[a
.p
])
94 // helper for filterValid
96 const piece
= this.getPiece(x
, y
);
97 if (V
.ALICE_PIECES
[piece
])
98 // From the other side of the mirror
99 this.board
[x
][y
] = this.getColor(x
, y
) + V
.ALICE_PIECES
[piece
];
101 // From the other other side :)
102 this.board
[x
][y
] = this.getColor(x
, y
) + V
.ALICE_CODES
[piece
];
106 const color
= this.turn
;
107 const oppCol
= C
.GetOppTurn(color
);
108 const kingPos
= this.searchKingPos(color
)[0];
109 const kingPiece
= this.getPiece(kingPos
[0], kingPos
[1]);
110 return super.filterValid(moves
).filter(m
=> {
111 // A move must also be legal on the board it is played:
112 // Shortcut if the moving piece and king are on different sides
114 !this.isKing(0, 0, m
.vanish
[0].p
) &&
115 !this.fromSameWorld(kingPiece
, m
.vanish
[0].p
)
120 m
.appear
.forEach(a
=> this.toggleWorld(a
.x
, a
.y
));
121 const kingAppear
= m
.appear
.find(a
=> this.isKing(0, 0, a
.p
));
122 const target
= [kingAppear
? [kingAppear
.x
, kingAppear
.y
] : kingPos
];
123 const res
= this.underCheck(target
, oppCol
);
124 m
.appear
.forEach(a
=> this.toggleWorld(a
.x
, a
.y
));