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