1 class AliceRules
extends ChessRUles
3 // TODO: more general double correspondance normal <--> alice
4 static get ALICE_PIECES()
6 return ['s','t','u','c','o','l']; //king is 'l'
11 return (this.ALICE_PIECES
.includes(b
[1]) ? "Alice/" : "") + b
;
14 getPotentialMovesFrom([x
,y
])
16 // Build board1+board2 from complete board
17 let board1
= doubleArray(sizeX
, sizeY
, "");
18 let board2
= doubleArray(sizeX
, sizeY
, "");
19 const [sizeX
,sizeY
] = variantRules
.size
;
20 for (let i
=0; i
<sizeX
; i
++)
22 for (let j
=0; j
<sizeY
; j
++)
24 const piece
= this.getPiece(i
,j
);
25 if (this.ALICE_PIECES
.includes(piece
))
26 board2
[i
][j
] = this.board
[i
][j
];
28 board1
[i
][j
] = this.board
[i
][j
];
31 let saveBoard
= JSON
.parse(JSON
.stringify(this.board
));
33 // Search valid moves on both boards
40 this.board
= saveBoard
;
42 // Finally filter impossible moves
49 // 1 where is king ? if board1 then build it, if board2 then build it. then check.
50 const color
= this.turn
;
52 let res
= this.isAttacked(this.kingPos
[color
], this.getOppCol(color
));
58 //getCheckSquares(move)
60 // TODO: pieces change side!
61 static PlayOnBoard(board
, move)
63 for (let psq
of move.vanish
)
64 board
[psq
.x
][psq
.y
] = VariantRules
.EMPTY
;
65 for (let psq
of move.appear
)
66 board
[psq
.x
][psq
.y
] = psq
.c
+ psq
.p
;
68 static UndoOnBoard(board
, move)
70 for (let psq
of move.appear
)
71 board
[psq
.x
][psq
.y
] = VariantRules
.EMPTY
;
72 for (let psq
of move.vanish
)
73 board
[psq
.x
][psq
.y
] = psq
.c
+ psq
.p
;
78 const color
= this.turn
;
79 // No valid move: stalemate or checkmate?
80 // TODO: here also, need to build the board with king on it
81 if (!this.isAttacked(this.kingPos
[color
], this.getOppCol(color
)))
84 return color
== "w" ? "0-1" : "1-0";