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