Copycat almost ok - some checks undetected
[xogo.git] / variants / Copycat / class.js
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,
9 styles: ["atomic", "capture", "crazyhouse", "cylinder", "dark", "zen"]
10 };
11 }
12
13 getPotentialMovesFrom([x, y], color) {
14 let moves = super.getPotentialMovesFrom([x, y], color);
15 // Expand potential moves if attacking friendly pieces.
16 const piece = this.getPiece(x,y);
17 if (['p', 'k'].includes(piece))
18 return moves;
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 }
31 if (this.onBoard(i, j) && this.getColor(i, j) == this.turn) {
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 => {
46 if (
47 (piece != 'q' && type != piece) ||
48 (piece == 'q' && type == 'n')
49 ) {
50 Array.prototype.push.apply(moves,
51 super.getPotentialMovesOf(type, [x, y]));
52 }
53 });
54 return moves;
55 }
56
57 underAttack([x, y], oppCols) {
58 if (super.underAttack([x, y], oppCols)
59 return true;
60 //TODO
61 }
62
63 };