Commit | Line | Data |
---|---|---|
a548cb4e | 1 | import ChessRules from "/base_rules.js"; |
f3e90e30 | 2 | import AbstractAntikingRules from "/variants/_Antiking/class.js"; |
a548cb4e | 3 | |
f3e90e30 | 4 | export 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 | ||
31 | genRandInitFen() { | |
32 | // Always deterministic setup | |
33 | return ( | |
34 | '2prbkqA/2p1nnbr/2pppppp/8/8/PPPPPP2/RBNN1P2/aQKBRP2 w 0 ' + | |
35 | '{"flags":"KAka"}' | |
36 | ); | |
37 | } | |
38 | ||
39 | // (Anti)King flags at 1 (true) if they can knight-jump | |
f3e90e30 | 40 | setFlags(fenFlags) { |
a548cb4e BA |
41 | this.kingFlags = { w: {}, b: {} }; |
42 | for (let i=0; i<fenFlags.length; i++) { | |
43 | const white = fenFlags.charCodeAt(i) <= 90; | |
f3e90e30 | 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( | |
52 | ['w', 'b'].map(c => Object.keys(this.kingFlags[c])) | |
53 | ).join("") | |
54 | ); | |
55 | } | |
56 | ||
57 | getPotentialMovesFrom([x, y]) { | |
58 | const color = this.turn; | |
59 | let moves = super.getPotentialMovesFrom([x, y]); | |
f3e90e30 | 60 | if (this.kingFlags[color][this.getPiece(x, y)]) { |
a548cb4e BA |
61 | // Allow knight jump (king or antiking) |
62 | const knightMoves = super.getPotentialMovesOf('n', [x, y]); | |
63 | // Remove captures (TODO: could be done more efficiently...) | |
f3e90e30 | 64 | moves = moves.concat(knightMoves.filter(m => m.vanish.length == 1)); |
a548cb4e BA |
65 | } |
66 | return moves; | |
67 | } | |
68 | ||
69 | prePlay(move) { | |
70 | super.prePlay(move); | |
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]; | |
75 | } | |
76 | ||
77 | }; |