9b8af78ecd41905b98d7f8d92da77c33419d6628
1 import ChessRules
from "/base_rules.js";
2 import AbstractAntikingRules
from "/variants/_Antiking/class.js";
4 export default class Antiking1Rules
extends AbstractAntikingRules
{
14 const pawnShift
= (color
== "w" ? -1 : 1);
15 let res
= super.pieces(color
, x
, y
);
18 steps: [[pawnShift
, 1], [pawnShift
, -1]],
24 steps: [[pawnShift
, 0]],
32 // Always deterministic setup
34 '2prbkqA/2p1nnbr/2pppppp/8/8/PPPPPP2/RBNN1P2/aQKBRP2 w 0 ' +
39 // (Anti)King flags at 1 (true) if they can knight-jump
41 this.kingFlags
= { w: {}, b: {} };
42 for (let i
=0; i
<fenFlags
.length
; i
++) {
43 const white
= fenFlags
.charCodeAt(i
) <= 90;
44 const curChar
= fenFlags
.charAt(i
).toLowerCase();
45 this.kingFlags
[white
? 'w' : 'b'][curChar
] = true;
51 Array
.prototype.concat
.apply(
52 ['w', 'b'].map(c
=> Object
.keys(this.kingFlags
[c
]))
57 getPotentialMovesFrom([x
, y
]) {
58 const color
= this.turn
;
59 let moves
= super.getPotentialMovesFrom([x
, y
]);
60 if (this.kingFlags
[color
][this.getPiece(x
, y
)]) {
61 // Allow knight jump (king or antiking)
62 const knightMoves
= super.getPotentialMovesOf('n', [x
, y
]);
63 // Remove captures (TODO: could be done more efficiently...)
64 moves
= moves
.concat(knightMoves
.filter(m
=> m
.vanish
.length
== 1));
71 // Update king+antiking flags
72 const piece
= move.vanish
[0].p
;
73 if (this.isKing(0, 0, piece
))
74 delete this.kingFlags
[move.vanish
[0].c
][piece
];