Commit | Line | Data |
---|---|---|
f55a0a67 | 1 | import ChessRules from "/base_rules.js"; |
f3e90e30 BA |
2 | import {ArrayFun} from "/utils/array.js"; |
3 | import {Random} from "/utils/alea.js"; | |
7c038235 | 4 | import {FenUtil} from "/utils/setupPieces.js"; |
f55a0a67 BA |
5 | |
6 | export default class AlapoRules extends ChessRules { | |
7 | ||
6b9320bb BA |
8 | static get Options() { |
9 | return { | |
10 | select: C.Options.select, | |
11 | styles: C.Options.styles.filter(s => s != "teleport") | |
12 | }; | |
13 | } | |
14 | ||
f55a0a67 BA |
15 | get hasFlags() { |
16 | return false; | |
17 | } | |
18 | get hasEnpassant() { | |
19 | return false; | |
20 | } | |
21 | ||
22 | getSvgChessboard() { | |
23 | let board = super.getSvgChessboard().slice(0, -6); | |
24 | // Add lines to delimitate goals | |
25 | board += ` | |
26 | <line x1="0" y1="10" x2="60" y2="10" stroke="black" stroke-width="0.1"/> | |
27 | <line x1="0" y1="50" x2="60" y2="50" stroke="black" stroke-width="0.1"/> | |
28 | </svg>`; | |
29 | return board; | |
30 | } | |
31 | ||
f31de5e4 | 32 | genRandInitBaseFen() { |
7c038235 BA |
33 | const s = |
34 | FenUtil.setupPieces(['r', 'b', 'q', 'q', 'b', 'r'], {diffCol: ['b']}); | |
35 | const piece2pawn = { | |
36 | r: 't', | |
37 | q: 's', | |
38 | b: 'c' | |
39 | }; | |
40 | const fen = ( | |
41 | s.b.join("") + "/" + | |
42 | s.b.map(p => piece2pawn[p]).join("") + | |
43 | "/6/6/" + | |
44 | s.w.map(p => piece2pawn[p].toUpperCase()).join("") + "/" + | |
45 | s.w.join("").toUpperCase() | |
46 | ); | |
f31de5e4 | 47 | return { fen: fen, o: {} }; |
f55a0a67 BA |
48 | } |
49 | ||
65cf1690 | 50 | // Triangles are rotated from opponent viewpoint (=> suffix "_inv") |
f55a0a67 | 51 | pieces(color, x, y) { |
65cf1690 | 52 | const allSpecs = super.pieces(color, x, y); |
f55a0a67 | 53 | return { |
65cf1690 BA |
54 | 'r': allSpecs['r'], |
55 | 'q': allSpecs['q'], | |
56 | 'b': Object.assign({}, allSpecs['b'], | |
57 | {"class": "bishop" + (this.playerColor != color ? "_inv" : "")}), | |
f55a0a67 BA |
58 | 's': { //"square" |
59 | "class": "babyrook", | |
33b42748 | 60 | both: [ |
f55a0a67 BA |
61 | { |
62 | steps: [[0, 1], [0, -1], [1, 0], [-1, 0]], | |
63 | range: 1 | |
64 | } | |
65 | ] | |
66 | }, | |
67 | 'c': { //"circle" | |
68 | "class": "babyqueen", | |
33b42748 | 69 | both: [ |
f55a0a67 BA |
70 | { |
71 | steps: [ | |
72 | [0, 1], [0, -1], [1, 0], [-1, 0], | |
73 | [1, 1], [1, -1], [-1, 1], [-1, -1] | |
74 | ], | |
75 | range: 1 | |
76 | } | |
77 | ] | |
78 | }, | |
79 | 't': { //"triangle" | |
80 | "class": "babybishop" + (this.playerColor != color ? "_inv" : ""), | |
33b42748 | 81 | both: [ |
f55a0a67 BA |
82 | { |
83 | steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]], | |
84 | range: 1 | |
85 | } | |
86 | ] | |
87 | } | |
88 | }; | |
89 | } | |
90 | ||
91 | get size() { | |
92 | return { | |
93 | x: 6, | |
94 | y: 6 | |
95 | }; | |
96 | } | |
97 | ||
98 | filterValid(moves) { | |
99 | return moves; | |
100 | } | |
101 | ||
102 | getCurrentScore() { | |
103 | // Try both colors (to detect potential suicides) | |
104 | let won = {}; | |
105 | for (let c of ['w', 'b']) { | |
106 | const oppCol = C.GetOppCol(c); | |
107 | const goal = (c == 'w' ? 0 : 5); | |
108 | won[c] = this.board[goal].some((b,j) => { | |
109 | return ( | |
110 | this.getColor(goal, j) == c && | |
6b9320bb BA |
111 | !this.findCapturesOn( |
112 | [goal, j], | |
113 | { | |
114 | one: true, | |
115 | oppCol: oppCol, | |
116 | segments: this.options["cylinder"] | |
117 | } | |
118 | ) | |
f55a0a67 BA |
119 | ); |
120 | }); | |
121 | } | |
122 | if (won['w'] && won['b']) | |
123 | return "?"; //no idea who won, not relevant anyway :) | |
124 | return (won['w'] ? "1-0" : (won['b'] ? "0-1" : "*")); | |
125 | } | |
126 | ||
127 | }; |