2c417c5e41b4760edede600905a62defac603728
1 import ChessRules
from "/base_rules.js";
3 export default class CopycatRules
extends ChessRules
{
7 select: C
.Options
.select
,
8 input: C
.Options
.input
,
9 styles: ["atomic", "capture", "crazyhouse", "cylinder", "dark", "zen"]
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
))
20 const steps
= this.pieces()[piece
].both
[0].steps
;
22 let [i
, j
] = [x
+ s
[0], y
+ s
[1]];
25 this.board
[i
][j
] == "" &&
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;
37 else if (attacked
== 'q') {
39 movements
['r'] = true;
41 movements
['b'] = true;
45 Object
.keys(movements
).forEach(type
=> {
47 (piece
!= 'q' && type
!= piece
) ||
48 (piece
== 'q' && type
== 'n')
50 Array
.prototype.push
.apply(moves
,
51 super.getPotentialMovesOf(type
, [x
, y
]));
57 underAttack([x
, y
], oppCols
) {
58 if (super.underAttack([x
, y
], oppCols
)