f8406b7ebd41ba718c31f7a83ad11c53b1130a8b
1 import ChessRules
from "/base_rules.js";
2 import AbstractAntikingRules
from "/variants/AbstractAntiking.js";
4 export class Antiking1Rules
extends AbstractAntikingRules
{
30 const pawnShift
= (color
== "w" ? -1 : 1);
31 let res
= super.pieces(color
, x
, y
);
34 steps: [[pawnShift
, 1], [pawnShift
, -1]],
40 steps: [[pawnShift
, 0]],
48 // Always deterministic setup
50 '2prbkqA/2p1nnbr/2pppppp/8/8/PPPPPP2/RBNN1P2/aQKBRP2 w 0 ' +
55 // (Anti)King flags at 1 (true) if they can knight-jump
57 this.kingFlags
= { w: {}, b: {} };
58 for (let i
=0; i
<fenFlags
.length
; i
++) {
59 const white
= fenFlags
.charCodeAt(i
) <= 90;
60 const curChar
= fenFlags
.charCodeAt(i
).toLowerCase();
61 this.kingFlags
[white
? 'w' : 'b'][curChar
] = true;
67 Array
.prototype.concat
.apply(
68 ['w', 'b'].map(c
=> Object
.keys(this.kingFlags
[c
]))
73 getPotentialMovesFrom([x
, y
]) {
74 const color
= this.turn
;
75 let moves
= super.getPotentialMovesFrom([x
, y
]);
76 if (this.kingFlags
[color
][piece
]) {
77 // Allow knight jump (king or antiking)
78 const knightMoves
= super.getPotentialMovesOf('n', [x
, y
]);
79 // Remove captures (TODO: could be done more efficiently...)
80 moves
= moves
.concat(knightJumps
.filter(m
=> m
.vanish
.length
== 1));
87 // Update king+antiking flags
88 const piece
= move.vanish
[0].p
;
89 if (this.isKing(0, 0, piece
))
90 delete this.kingFlags
[move.vanish
[0].c
][piece
];