- static get PIECES() {
- return (
- ChessRules.PIECES.concat(
- Object.keys(V.IMMOBILIZE_DECODE)).concat(
- [V.BANANA, V.BOMB, V.EGG, V.MUSHROOM, V.INVISIBLE_QUEEN])
- );
- }
-
- getPpath(b) {
- let prefix = "";
- if (
- b[0] == 'a' ||
- b[1] == V.INVISIBLE_QUEEN ||
- Object.keys(V.IMMOBILIZE_DECODE).includes(b[1])
- ) {
- prefix = "Chakart/";
- }
- return prefix + b;
- }
-
- getPPpath(m) {
- if (!!m.promoteInto) return m.promoteInto;
- if (m.appear.length == 0 && m.vanish.length == 1)
- // King 'remote shell capture', on an adjacent square:
- return this.getPpath(m.vanish[0].c + m.vanish[0].p);
- let piece = m.appear[0].p;
- if (Object.keys(V.IMMOBILIZE_DECODE).includes(piece))
- // Promotion by capture into immobilized piece: do not reveal!
- piece = V.IMMOBILIZE_DECODE[piece];
- return this.getPpath(m.appear[0].c + piece);
- }
-
- static ParseFen(fen) {
- const fenParts = fen.split(" ");
- return Object.assign(
- ChessRules.ParseFen(fen),
- { captured: fenParts[4] }
- );
- }
-
- static IsGoodFen(fen) {
- if (!ChessRules.IsGoodFen(fen)) return false;
- const captured = V.ParseFen(fen).captured;
- if (!captured || !captured.match(/^[0-9]{12,12}$/)) return false;
- return true;
- }
-
- // King can be l or L (immobilized) --> similar to Alice variant
- static IsGoodPosition(position) {
- if (position.length == 0) return false;
- const rows = position.split("/");
- if (rows.length != V.size.x) return false;
- let kings = { "k": 0, "K": 0, 'l': 0, 'L': 0 };
- for (let row of rows) {
- let sumElts = 0;
- for (let i = 0; i < row.length; i++) {
- if (['K', 'k', 'L', 'l'].includes(row[i])) kings[row[i]]++;
- if (V.PIECES.includes(row[i].toLowerCase())) sumElts++;
- else {
- const num = parseInt(row[i], 10);
- if (isNaN(num)) return false;
- sumElts += num;
- }
- }
- if (sumElts != V.size.y) return false;
- }
- if (kings['k'] + kings['l'] == 0 || kings['K'] + kings['L'] == 0)
- return false;
- return true;
- }
-
- static IsGoodFlags(flags) {
- // 4 for Peach + Mario w, b
- return !!flags.match(/^[01]{4,4}$/);
- }
-