Commit | Line | Data |
---|---|---|
a548cb4e | 1 | import ChessRules from "/base_rules.js"; |
f3e90e30 BA |
2 | import AbstractAntikingRules from "/variants/_Antiking/class.js"; |
3 | import {Random} from "/utils/alea.js"; | |
a548cb4e | 4 | |
f3e90e30 | 5 | export default class Antiking2Rules extends AbstractAntikingRules { |
a548cb4e BA |
6 | |
7 | static get Options() { | |
8 | return { | |
f3e90e30 | 9 | select: C.Options.select, |
a548cb4e BA |
10 | styles: A.Options.styles.concat("cylinder") |
11 | }; | |
12 | } | |
13 | ||
f31de5e4 BA |
14 | genRandInitBaseFen() { |
15 | const baseFen = super.genRandInitBaseFen(); | |
a548cb4e BA |
16 | // Just add an antiking on 3rd ranks |
17 | let akPos = [3, 3]; | |
18 | if (this.options.randomness >= 1) { | |
19 | akPos[0] = Random.randInt(this.size.y); | |
20 | if (this.options.randomness == 2) | |
21 | akPos[1] = Random.randInt(this.size.y); | |
22 | else | |
23 | akPos[1] = akPos[0]; | |
24 | } | |
f3e90e30 BA |
25 | const antikingLine = (color) => { |
26 | const [idx, symbol] = (color == 'w' ? [0, 'a'] : [1, 'A']); | |
27 | return ( | |
28 | (akPos[idx] > 0 ? akPos[idx] : "") + symbol + | |
29 | (akPos[idx] < this.size.y - 1 | |
30 | ? C.FenEmptySquares(this.size.y - 1 - akPos[idx]) | |
31 | : "") | |
32 | ); | |
33 | }; | |
f31de5e4 BA |
34 | return { |
35 | fen: baseFen.fen.replace("p/8", "p/" + antikingLine('b')) | |
36 | .replace("8/P", antikingLine('w') + "/P"), | |
37 | o: baseFen.o | |
38 | }; | |
39 | } | |
40 | ||
41 | getCastleMoves([x, y]) { | |
42 | if (this.getPiece(x, y) == 'a') | |
43 | return []; | |
44 | return super.getCastleMoves([x, y]); | |
45 | } | |
46 | ||
47 | updateCastleFlags(move) { | |
48 | if (move.vanish.length > 0 && move.vanish[0].p == 'a') | |
49 | return; | |
50 | super.updateCastleFlags(move); | |
a548cb4e BA |
51 | } |
52 | ||
53 | }; |