Some thoughts about Coregal
[xogo.git] / variants / Copycat / class.js
1 import ChessRules from "/base_rules.js";
2
3 // TODO: there was an issue: I forgot which.. TOFIND and TOFIX :)
4
5 export default class CopycatRules extends ChessRules {
6
7 static get Options() {
8 return {
9 select: C.Options.select,
10 input: C.Options.input,
11 styles: C.Options.styles.filter(s => !["madrasi", "zen"].includes(s))
12 };
13 }
14
15 getStepSpec(color, x, y) {
16 let res = super.getStepSpec(color, x, y);
17 const piece = this.getPiece(x,y);
18 if (['p', 'k'].includes(piece))
19 return res;
20 // Now check if the piece at x, y attack some friendly one (enhancement)
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 }
33 if (this.onBoard(i, j) && this.getColor(i, j) == color) {
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 => {
48 if ((piece != 'q' && type != piece) || (piece == 'q' && type == 'n'))
49 res.both.push(this.pieces()[type].both[0]);
50 });
51 return res;
52 }
53
54 };