From: Benjamin Auder Date: Sun, 24 Jan 2021 23:49:16 +0000 (+0100) Subject: Fix Makruk/Makpong X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/css/static/current/%7B%7B%20targetUrl%20%7D%7D?a=commitdiff_plain;h=f5cd0fb81ec9bd790d812c9ad02587e50427fcdf;p=vchess.git Fix Makruk/Makpong --- diff --git a/client/src/translations/rules/Makpong/en.pug b/client/src/translations/rules/Makpong/en.pug index 522cb58b..561485e8 100644 --- a/client/src/translations/rules/Makpong/en.pug +++ b/client/src/translations/rules/Makpong/en.pug @@ -2,10 +2,10 @@ p.boxed | Makruk, with kings immobilized by checks. p - | Everything goes as in the variant + | Everything goes as in a(href="/#/variants/Makruk") Makruk - | , but the king isn't allowed to move when he's under check: - | one has to capture the attacker, or intercept the attack if possible. + | , but the king isn't allowed to move when he's under check + | except to capture the attacker. figure.diagram-container .diagram diff --git a/client/src/translations/rules/Makpong/es.pug b/client/src/translations/rules/Makpong/es.pug index d3e2cf7a..11df52e8 100644 --- a/client/src/translations/rules/Makpong/es.pug +++ b/client/src/translations/rules/Makpong/es.pug @@ -2,10 +2,10 @@ p.boxed | Makruk, con reyes inmovilizados por los jaques. p - | Todo va como en la variante + | Todo va como en a(href="/#/variants/Makruk") Makruk - | , pero el rey no puede moverse cuando está en jaque: - | debemos capturar al agresor, o interponer una pieza si es posible. + | , pero el rey no puede moverse cuando está en jaque + | excepto por capturar al agresor. figure.diagram-container .diagram diff --git a/client/src/translations/rules/Makpong/fr.pug b/client/src/translations/rules/Makpong/fr.pug index dd24d4af..d90c63f9 100644 --- a/client/src/translations/rules/Makpong/fr.pug +++ b/client/src/translations/rules/Makpong/fr.pug @@ -2,10 +2,10 @@ p.boxed | Makruk, avec rois immobilisés par les échecs. p - | Tout se déroule comme dans la variante + | Tout se déroule comme au a(href="/#/variants/Makruk") Makruk - | , mais le roi n'a pas le droit de bouger lorsqu'il est en échec : - | il faut capturer l'assaillant, ou interposer une pièce si possible. + | , mais le roi n'a pas le droit de bouger lorsqu'il est en échec + | sauf pour capturer l'attaquant. figure.diagram-container .diagram diff --git a/client/src/variants/Makpong.js b/client/src/variants/Makpong.js index 05766651..885de3ef 100644 --- a/client/src/variants/Makpong.js +++ b/client/src/variants/Makpong.js @@ -4,11 +4,47 @@ export class MakpongRules extends MakrukRules { filterValid(moves) { const color = this.turn; - if (this.underCheck(color)) { - // Filter out all moves involving king - return super.filterValid(moves.filter(m => m.vanish[0].p != V.KING)); - } - return super.filterValid(moves); + if (!this.underCheck(color)) return super.filterValid(moves); + // Filter out all moves involving king, except for capturing a + // potential attacker. + const pawnAttack = (color == 'w' ? -1 : 1); + return super.filterValid(moves.filter(m => { + const p = (m.vanish.length == 2 ? m.vanish[1].p : null); + return ( + m.vanish[0].p != V.KING || + ( + m.vanish.length == 2 && + ( + ( + p == V.PAWN && + m.end.x - m.start.x == pawnAttack && + Math.abs(m.end.y - m.start.y) == 1 + ) + || + ( + p == V.ROOK && + (m.end.x == m.start.x || m.end.y == m.start.y) + ) + || + ( + [V.PROMOTED, V.QUEEN].includes(p) && + m.end.x != m.start.x && m.end.y != m.start.y + ) + || + ( + p == V.BISHOP && + ( + m.end.x - m.start.x == pawnAttack || + ( + m.end.x - m.start.x == -pawnAttack && + Math.abs(m.end.y - m.start.y) == 1 + ) + ) + ) + ) + ) + ); + })); } }; diff --git a/client/src/variants/Makruk.js b/client/src/variants/Makruk.js index 55617025..75fb1da2 100644 --- a/client/src/variants/Makruk.js +++ b/client/src/variants/Makruk.js @@ -109,6 +109,12 @@ export class MakrukRules extends ChessRules { ); } + isAttacked(sq, color) { + return ( + super.isAttacked(sq, color) || this.isAttackedByPromoted(sq, color) + ); + } + isAttackedByBishop(sq, color) { const forward = (color == 'w' ? 1 : -1); return this.isAttackedBySlideNJump( @@ -130,6 +136,16 @@ export class MakrukRules extends ChessRules { ); } + isAttackedByPromoted(sq, color) { + return super.isAttackedBySlideNJump( + sq, + color, + V.PROMOTED, + V.steps[V.BISHOP], + "oneStep" + ); + } + static get VALUES() { return { p: 1,