X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=34f0e7e13e6644134fada8aab2601ef4d05d7101;hb=f3336fdf24e48ef54aee71426d979f81ef744c14;hp=5717276b0cee3ee4e46eb706bc7f1d3029ddfc47;hpb=e5cea9ca0c427305223cf75b2df6a533e640510f;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 5717276..34f0e7e 100644 --- a/base_rules.js +++ b/base_rules.js @@ -7,6 +7,10 @@ import Move from "/utils/Move.js"; // NOTE: ChessRules is aliased as window.C, and variants as window.V export default class ChessRules { + static get Aliases() { + return {'C': ChessRules}; + } + ///////////////////////// // VARIANT SPECIFICATIONS @@ -26,11 +30,18 @@ export default class ChessRules { { label: "Asymmetric random", value: 2 } ] }], - check: [{ - label: "Capture king?", - defaut: false, - variable: "taking" - }], + check: [ + { + label: "Capture king", + defaut: false, + variable: "taking" + }, + { + label: "Falling pawn", + defaut: false, + variable: "pawnfall" + } + ], // Game modifiers (using "elementary variants"). Default: false styles: [ "atomic", @@ -373,8 +384,6 @@ export default class ChessRules { // Fen string fully describes the game state constructor(o) { - window.C = ChessRules; //easier alias - this.options = o.options; this.playerColor = o.color; this.afterPlay = o.afterPlay; @@ -859,7 +868,7 @@ export default class ChessRules { // Touch screen, dragend touchLocation = e.changedTouches[0]; if (touchLocation) - return {x: touchLocation.pageX, y: touchLocation.pageY}; + return {x: touchLocation.clientX, y: touchLocation.clientY}; return [0, 0]; //Big trouble here =) } @@ -909,6 +918,9 @@ export default class ChessRules { e.preventDefault(); centerOnCursor(curPiece, e); } + else if (e.changedTouches && e.changedTouches.length >= 1) + // Attempt to prevent horizontal swipe... + e.preventDefault(); }; const mouseup = (e) => { @@ -949,6 +961,7 @@ export default class ChessRules { document.addEventListener("touchmove", mousemove, {passive: false}); document.addEventListener("touchend", mouseup, {passive: false}); } + // TODO: onpointerdown/move/up ? See reveal.js /controllers/touch.js } showChoices(moves, r) { @@ -1541,15 +1554,16 @@ export default class ChessRules { return !!enpassantMove ? [enpassantMove] : []; } - // Consider all potential promotions: + // Consider all potential promotions. + // NOTE: "promotions" arg = special override for Hiddenqueen variant addPawnMoves([x1, y1], [x2, y2], moves, promotions) { let finalPieces = ["p"]; const color = this.getColor(x1, y1); const oppCol = C.GetOppCol(color); const lastRank = (color == "w" ? 0 : this.size.x - 1); - if (x2 == lastRank && (!this.options["rifle"] || this.board[x2][y2] == "")) - { - // promotions arg: special override for Hiddenqueen variant + const promotionOk = + x2 == lastRank && (!this.options["rifle"] || this.board[x2][y2] == ""); + if (promotionOk && !this.options["pawnfall"]) { if ( this.options["cannibal"] && this.board[x2][y2] != "" && @@ -1562,8 +1576,15 @@ export default class ChessRules { finalPieces = this.pawnSpecs.promotions; } for (let piece of finalPieces) { - const tr = (piece != "p" ? { c: color, p: piece } : null); - moves.push(this.getBasicMove([x1, y1], [x2, y2], tr)); + const tr = !this.options["pawnfall"] && piece != "p" + ? { c: color, p: piece } + : null; + let newMove = this.getBasicMove([x1, y1], [x2, y2], tr); + if (promotionOk && this.options["pawnfall"]) { + newMove.appear.shift(); + newMove.pawnfall = true; //required in prePlay() + } + moves.push(newMove); } } @@ -1775,7 +1796,7 @@ export default class ChessRules { // Is (king at) given position under check by "color" ? underCheck([x, y], color) { - if (this.taking || this.options["dark"]) return false; + if (this.options["taking"] || this.options["dark"]) return false; color = color || C.GetOppCol(this.getColor(x, y)); const pieces = this.pieces(color); return Object.keys(pieces).some(p => { @@ -1845,7 +1866,7 @@ export default class ChessRules { return res; }); } - if (this.taking || this.options["dark"]) return moves; + if (this.options["taking"] || this.options["dark"]) return moves; const kingPos = this.searchKingPos(color); let filtered = {}; //avoid re-checking similar moves (promotions...) return moves.filter(m => { @@ -1951,7 +1972,7 @@ export default class ChessRules { } } const minSize = Math.min(move.appear.length, move.vanish.length); - if (this.hasReserve) { + if (this.hasReserve && !move.pawnfall) { const color = this.turn; for (let i=minSize; i