Commit | Line | Data |
---|---|---|
5c1c7bce BA |
1 | import { ChessRules, Move, PiPo } from "@/base_rules"; |
2 | import { ArrayFun } from "@/utils/array"; | |
3 | import { randInt, sample } from "@/utils/alea"; | |
4 | ||
5 | export class CoregalRules extends ChessRules { | |
6 | ||
5c1c7bce BA |
7 | genRandInitBaseFen() { |
8 | const s = FenUtil.setupPieces( | |
9 | ['r', 'n', 'b', 'l', 'k', 'b', 'n', 'r'], | |
10 | { | |
11 | randomness: this.options["randomness"], | |
12 | between: [{p1: 'k', p2: 'r'}, {p1: 'l', p2: 'r'}], | |
13 | diffCol: ['b'], | |
dcfaab5d BA |
14 | // 'k' and 'l' useful only to get relative position |
15 | flags: ['r', 'k', 'l'] | |
5c1c7bce BA |
16 | } |
17 | ); | |
18 | return { | |
19 | fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + | |
20 | s.w.join("").toUpperCase(), | |
dcfaab5d BA |
21 | // TODO: re-arrange flags, use another init variable "relPos" (in o) |
22 | // (maybe after FEN parsing, easier?) | |
23 | o: {flags: s.flags + s.flags} //second set for royal queen | |
5c1c7bce BA |
24 | }; |
25 | } | |
26 | ||
27 | pieces() { | |
28 | let res = super.pieces(); | |
29 | res['l'] = JSON.parse(JSON.stringify(res['q'])); | |
dcfaab5d | 30 | // TODO: CSS royal queen symbol (with cross?) |
5c1c7bce BA |
31 | res['l']["class"] = "royal_queen"; |
32 | return res; | |
33 | } | |
34 | ||
dcfaab5d | 35 | // TODO: something like that indeed (+ flags to FEN) |
5c1c7bce | 36 | setFlags(fenflags) { |
dcfaab5d BA |
37 | this.castleFlags = { |
38 | 'k': { 'w': [...Array(4)], b: [...Array(4)] }, | |
39 | 'l': { 'w': [...Array(4)], b: [...Array(4)] } | |
40 | }; | |
5c1c7bce | 41 | for (let i = 0; i < 8; i++) { |
dcfaab5d | 42 | this.castleFlags[i < 4 ? "k" : "l"][i % 4 < 2 ? "w" : "b"] = |
5c1c7bce BA |
43 | parseInt(fenflags.charAt(i), 10); |
44 | } | |
45 | } | |
46 | ||
47 | isKing(x, y, p) { | |
48 | if (!p) | |
49 | p = this.getPiece(x, y); | |
50 | ['k', 'l'].includes(p); //no cannibal mode | |
51 | } | |
52 | ||
53 | getCastleMoves([x, y]) { | |
dcfaab5d BA |
54 | const c = this.getColor(x, y), |
55 | p = this.getPiece(x, y); | |
5c1c7bce BA |
56 | // Relative position of the selected piece: left or right ? |
57 | // If left: small castle left, large castle right. | |
58 | // If right: usual situation. | |
5c1c7bce | 59 | const finalSquares = [ |
dcfaab5d BA |
60 | this.relPos[c][p] == "left" ? [1, 2] : [2, 3], |
61 | this.relPos[c][p] == "right" ? [6, 5] : [5, 4] | |
5c1c7bce | 62 | ]; |
dcfaab5d BA |
63 | const moves = |
64 | super.getCastleMoves([x, y], finalSquares, null, this.castleFlags[p]); | |
5c1c7bce BA |
65 | return moves; |
66 | } | |
67 | ||
dcfaab5d BA |
68 | // TODO: updateFlags (just pass castleFlags arg) |
69 | ||
5c1c7bce | 70 | }; |