X-Git-Url: https://git.auder.net/images/diag_mark.svg?a=blobdiff_plain;f=variants%2F_Flip%2Fclass.js;fp=variants%2F_Flip%2Fclass.js;h=e2e2bf52c22a1959f9444d83db80fa2514b86974;hb=33b427488bb6ee5c505c3a024bccedbef763f80e;hp=0000000000000000000000000000000000000000;hpb=7bd7cba41f9c2222a29c62ddf8d83fbb46646a1d;p=xogo.git diff --git a/variants/_Flip/class.js b/variants/_Flip/class.js new file mode 100644 index 0000000..e2e2bf5 --- /dev/null +++ b/variants/_Flip/class.js @@ -0,0 +1,43 @@ +import ChessRules from "/base_rules.js"; + +export default class AbstractFlipRules extends ChessRules { + + // For games without captures (replaced by flips) + get hasEnpassant() { + return false; + } + canTake() { + return false; + } + filterValid(moves) { + return moves; + } + underCheck() { + return false; + } + + playOnBoard(move) { + super.playOnBoard(move); + this.flipColorOf(move.flips); + } + undoOnBoard(move) { + super.undoOnBoard(move); + this.flipColorOf(move.flips); + } + + flipColorOf(flips) { + for (let xy of flips) { + const newColor = C.GetOppCol(this.getColor(xy.x, xy.y)); + this.board[xy.x][xy.y] = newColor + this.board[xy.x][xy.y][1]; + } + } + + playVisual(move, r) { + super.playVisual(move, r); + move.flips.forEach(f => { + this.g_pieces[f.x][f.y].classList.toggle("white"); + this.g_pieces[f.x][f.y].classList.toggle("black"); + }); + } + +};