Commit | Line | Data |
---|---|---|
296f846a BA |
1 | import ChessRules from "/base_rules.js"; |
2 | ||
3 | export default class CopycatRules extends ChessRules { | |
4 | ||
5 | static get Options() { | |
6 | return { | |
7 | select: C.Options.select, | |
8 | input: C.Options.input, | |
a46d74c0 | 9 | styles: C.Options.styles.filter(s => !["madrasi", "zen"].includes(s)) |
296f846a BA |
10 | }; |
11 | } | |
12 | ||
a46d74c0 BA |
13 | getStepSpec(color, x, y) { |
14 | let res = super.getStepSpec(color, x, y); | |
296f846a BA |
15 | const piece = this.getPiece(x,y); |
16 | if (['p', 'k'].includes(piece)) | |
a46d74c0 BA |
17 | return res; |
18 | // Now check if the piece at x, y attack some friendly one (enhancement) | |
296f846a BA |
19 | let movements = {}; |
20 | const steps = this.pieces()[piece].both[0].steps; | |
21 | steps.forEach(s => { | |
22 | let [i, j] = [x + s[0], y + s[1]]; | |
23 | while ( | |
24 | this.onBoard(i, j) && | |
25 | this.board[i][j] == "" && | |
26 | piece != 'n' | |
27 | ) { | |
28 | i += s[0]; | |
29 | j += s[1]; | |
30 | } | |
a46d74c0 | 31 | if (this.onBoard(i, j) && this.getColor(i, j) == color) { |
296f846a BA |
32 | const attacked = this.getPiece(i, j); |
33 | if (['r', 'b', 'n'].includes(attacked)) { | |
34 | if (!movements[attacked]) | |
35 | movements[attacked] = true; | |
36 | } | |
37 | else if (attacked == 'q') { | |
38 | if (!movements['r']) | |
39 | movements['r'] = true; | |
40 | if (!movements['b']) | |
41 | movements['b'] = true; | |
42 | } | |
43 | } | |
44 | }); | |
45 | Object.keys(movements).forEach(type => { | |
a46d74c0 BA |
46 | if ((piece != 'q' && type != piece) || (piece == 'q' && type == 'n')) |
47 | res.both.push(this.pieces()[type].both[0]); | |
296f846a | 48 | }); |
a46d74c0 | 49 | return res; |
296f846a BA |
50 | } |
51 | ||
52 | }; |