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() {
44 getPieceType(x
, y
, p
) {
46 p
= super.getPiece(x
, y
);
47 return V
.ALICE_PIECES
[p
] || 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 // NOTE: castle & enPassant
76 // https://www.chessvariants.com/other.dir/alice.html
77 getPotentialMovesFrom([x
, y
]) {
78 return super.getPotentialMovesFrom([x
, y
]).filter(m
=> {
79 // Remove moves landing on occupied square on other board
81 this.board
[m
.end
.x
][m
.end
.y
] == "" ||
82 this.fromSameWorld(m
.vanish
[0].p
, m
.vanish
[1].p
)
85 // Apply Alice rule: go to the other side of the mirror
86 if (Object
.keys(V
.ALICE_CODES
).includes(m
.vanish
[0].p
))
88 m
.appear
.forEach(a
=> a
.p
= V
.ALICE_CODES
[a
.p
])
91 m
.appear
.forEach(a
=> a
.p
= V
.ALICE_PIECES
[a
.p
])
97 return ['k', 'l'].includes(symbol
);
101 const color
= this.turn
;
102 const inCheck
= this.underCheck(this.searchKingPos(color
));
103 let someLegalMove
= false;
104 // Search for legal moves: if any is found and
105 // does not change king world (if under check), then game not over.
106 for (let i
=0; i
<this.size
.x
; i
++) {
107 for (let j
=0; j
<this.size
.y
; j
++) {
108 if (this.getColor(i
, j
) == color
) {
109 const moves
= this.filterValid(this.getPotentialMovesFrom([i
, j
]));
114 moves
.some(m
=> m
.vanish
.every(v
=> !this.isKing(v
.p
)))
122 // Couldn't find any legal move
123 return (inCheck
? "1/2" : (color
== 'w' ? "0-1" : "1-0"));