A few fixes, specify Apocalypse rules, draft Arena
[xogo.git] / variants / Antiking1 / class.js
CommitLineData
a548cb4e 1import ChessRules from "/base_rules.js";
f3e90e30 2import AbstractAntikingRules from "/variants/_Antiking/class.js";
a548cb4e 3
f3e90e30 4export default class Antiking1Rules extends AbstractAntikingRules {
a548cb4e
BA
5
6 get hasCastle() {
7 return false;
8 }
f3e90e30
BA
9 get hasEnpassant() {
10 return false;
11 }
a548cb4e
BA
12
13 pieces(color, x, y) {
14 const pawnShift = (color == "w" ? -1 : 1);
15 let res = super.pieces(color, x, y);
16 res['p'].moves = [
17 {
18 steps: [[pawnShift, 1], [pawnShift, -1]],
19 range: 1
20 }
21 ];
22 res['p'].attack = [
23 {
24 steps: [[pawnShift, 0]],
25 range: 1
26 }
27 ];
28 return res;
29 }
30
f31de5e4 31 genRandInitBaseFen() {
a548cb4e 32 // Always deterministic setup
f31de5e4
BA
33 return {
34 fen: "2prbkqA/2p1nnbr/2pppppp/8/8/PPPPPP2/RBNN1P2/aQKBRP2 w 0",
35 o: {"flags": "KAka"}
36 };
a548cb4e
BA
37 }
38
39 // (Anti)King flags at 1 (true) if they can knight-jump
f31de5e4 40 setFlags(fenflags) {
a548cb4e 41 this.kingFlags = { w: {}, b: {} };
f31de5e4
BA
42 for (let i=0; i<fenflags.length; i++) {
43 const white = fenflags.charCodeAt(i) <= 90;
44 const curChar = fenflags.charAt(i).toLowerCase();
a548cb4e
BA
45 this.kingFlags[white ? 'w' : 'b'][curChar] = true;
46 }
47 }
48
49 getFlagsFen() {
50 return (
51 Array.prototype.concat.apply(
f31de5e4
BA
52 ['w', 'b'].map(c => {
53 const res = Object.keys(this.kingFlags[c]).join("");
54 return (c == 'w' ? res.toUpperCase() : res);
55 })
a548cb4e
BA
56 ).join("")
57 );
58 }
59
60 getPotentialMovesFrom([x, y]) {
61 const color = this.turn;
62 let moves = super.getPotentialMovesFrom([x, y]);
f3e90e30 63 if (this.kingFlags[color][this.getPiece(x, y)]) {
a548cb4e
BA
64 // Allow knight jump (king or antiking)
65 const knightMoves = super.getPotentialMovesOf('n', [x, y]);
66 // Remove captures (TODO: could be done more efficiently...)
f3e90e30 67 moves = moves.concat(knightMoves.filter(m => m.vanish.length == 1));
a548cb4e
BA
68 }
69 return moves;
70 }
71
72 prePlay(move) {
73 super.prePlay(move);
74 // Update king+antiking flags
75 const piece = move.vanish[0].p;
76 if (this.isKing(0, 0, piece))
77 delete this.kingFlags[move.vanish[0].c][piece];
78 }
79
80};