X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=variants%2F_SpecialCaptures%2Fclass.js;h=7d9f78673201aef77f22065f40a30955c04f01a3;hb=727f2e558776b14a29cb1552a05a88cc9a4b0297;hp=0c2a30043c9fdd9747aad7aecb0991b2ebf2347d;hpb=bc97fdd1302473b774cfb19e65dc3ed3ed388901;p=xogo.git diff --git a/variants/_SpecialCaptures/class.js b/variants/_SpecialCaptures/class.js index 0c2a300..7d9f786 100644 --- a/variants/_SpecialCaptures/class.js +++ b/variants/_SpecialCaptures/class.js @@ -22,7 +22,7 @@ export default class AbstractSpecialCaptureRules extends ChessRules { // Modify capturing moves among listed pincer moves addPincerCaptures(moves, byChameleon) { const steps = this.pieces()['p'].moves[0].steps; - const color = this.turn; + const color = moves[0].vanish[0].c; const oppCol = C.GetOppTurn(color); moves.forEach(m => { if (byChameleon && m.start.x != m.end.x && m.start.y != m.end.y) @@ -60,7 +60,7 @@ export default class AbstractSpecialCaptureRules extends ChessRules { } addCoordinatorCaptures(moves, byChameleon) { - const color = this.turn; + const color = moves[0].vanish[0].c; const oppCol = V.GetOppTurn(color); const kp = this.searchKingPos(color)[0]; moves.forEach(m => { @@ -90,7 +90,7 @@ export default class AbstractSpecialCaptureRules extends ChessRules { getLeaperCaptures([x, y], byChameleon, onlyOne) { // Look in every direction for captures const steps = this.pieces()['r'].moves[0].steps; - const color = this.turn; + const color = this.getColor(x, y); const oppCol = C.GetOppTurn(color); let moves = []; outerLoop: for (let step of steps) { @@ -154,12 +154,10 @@ export default class AbstractSpecialCaptureRules extends ChessRules { // type: nothing (freely, capture all), or pull or push, or "exclusive" addPushmePullyouCaptures(moves, byChameleon, type) { - if (moves.length == 0) - return; const [sx, sy] = [moves[0].start.x, moves[0].start.y]; const adjacentSteps = this.pieces()['r'].moves[0].steps; let capturingPullDir = {}; - const color = this.turn; + const color = moves[0].vanish[0].c; const oppCol = C.GetOppTurn(color); if (type != "push") { adjacentSteps.forEach(step => { @@ -216,14 +214,14 @@ export default class AbstractSpecialCaptureRules extends ChessRules { }); } - underAttack([x, y], oppCol) { + underAttack([x, y], oppCols) { // Generate all potential opponent moves, check if king captured. // TODO: do it more efficiently. const color = this.getColor(x, y); for (let i = 0; i < this.size.x; i++) { for (let j = 0; j < this.size.y; j++) { if ( - this.board[i][j] != "" && this.getColor(i, j) == oppCol && + this.board[i][j] != "" && oppCols.includes(this.getColor(i, j)) && this.getPotentialMovesFrom([i, j]).some(m => { return ( m.vanish.length >= 2 &&