Untested draft refactor both/moves/attack for pieces specs
[xogo.git] / variants / _Flip / class.js
CommitLineData
33b42748
BA
1import ChessRules from "/base_rules.js";
2
3export default class AbstractFlipRules extends ChessRules {
4
5 // For games without captures (replaced by flips)
6 get hasEnpassant() {
7 return false;
8 }
9 canTake() {
10 return false;
11 }
12 filterValid(moves) {
13 return moves;
14 }
15 underCheck() {
16 return false;
17 }
18
19 playOnBoard(move) {
20 super.playOnBoard(move);
21 this.flipColorOf(move.flips);
22 }
23 undoOnBoard(move) {
24 super.undoOnBoard(move);
25 this.flipColorOf(move.flips);
26 }
27
28 flipColorOf(flips) {
29 for (let xy of flips) {
30 const newColor = C.GetOppCol(this.getColor(xy.x, xy.y));
31 this.board[xy.x][xy.y] = newColor + this.board[xy.x][xy.y][1];
32 }
33 }
34
35 playVisual(move, r) {
36 super.playVisual(move, r);
37 move.flips.forEach(f => {
38 this.g_pieces[f.x][f.y].classList.toggle("white");
39 this.g_pieces[f.x][f.y].classList.toggle("black");
40 });
41 }
42
43};