X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKonane.js;h=7931347bc5db8a5ed09b1312cb25c75ca83f0f98;hb=HEAD;hp=6acc54bab61c013149762f893a38d8b547147dd6;hpb=c11afcdfa8678a27ea6c0822f6d3fef83967701b;p=vchess.git diff --git a/client/src/variants/Konane.js b/client/src/variants/Konane.js index 6acc54ba..7931347b 100644 --- a/client/src/variants/Konane.js +++ b/client/src/variants/Konane.js @@ -3,6 +3,10 @@ import { randInt } from "@/utils/alea"; export class KonaneRules extends ChessRules { + static get Options() { + return null; + } + static get HasFlags() { return false; } @@ -15,10 +19,6 @@ export class KonaneRules extends ChessRules { return true; } - static get PIECES() { - return V.PAWN; - } - getPiece() { return V.PAWN; } @@ -34,7 +34,7 @@ export class KonaneRules extends ChessRules { for (let row of rows) { let sumElts = 0; for (let i = 0; i < row.length; i++) { - if (V.PIECES.includes(row[i].toLowerCase())) sumElts++; + if (row[i].toLowerCase() == V.PAWN) sumElts++; else { const num = parseInt(row[i], 10); if (isNaN(num) || num <= 0) return false; @@ -53,13 +53,9 @@ export class KonaneRules extends ChessRules { ); } - setOtherVariables(fen) { - this.captures = []; //reinit for each move - } - - hoverHighlight(x, y) { - if (this.movesCount >= 2) return false; + hoverHighlight([x, y], side) { const c = this.turn; + if (this.movesCount >= 2 || (!!side && side != c)) return false; if (c == 'w') return (x == y && [0, 3, 4, 7].includes(x)); // "Black": search for empty square and allow nearby for (let i of [0, 3, 4, 7]) { @@ -105,57 +101,31 @@ export class KonaneRules extends ChessRules { const mv = this.doClick([x, y]); return (!!mv ? [mv] : []); } - const L = this.captures.length; - const c = (L > 0 ? this.captures[L-1] : null); const color = this.turn; const oppCol = V.GetOppCol(color); - let step = null; let moves = []; - if (!!c) { - if (x != c.end.x || y != c.end.y) return []; - step = [(c.end.x - c.start.x) / 2, (c.end.y - c.start.y) / 2]; - // Add move to adjacent empty square to mark "end of capture" - moves.push( - new Move({ - appear: [], - vanish: [], - start: { x: x, y: y }, - end: { x: x - step[0], y: y - step[1] } - }) - ); - } - // Examine captures from here - for (let s of (!!step ? [step] : V.steps[V.ROOK])) { - let [i, j] = [x + 2*s[0], y + 2*s[1]]; - if ( - !!c || //avoid redundant checks if continuation - ( - V.OnBoard(i, j) && - this.board[i][j] == V.EMPTY && - this.board[i - s[0]][j - s[1]] != V.EMPTY && - this.getColor(i - s[0], j - s[1]) == oppCol - ) - ) { - let mv = new Move({ - appear: [ - new PiPo({ x: i, y: j, c: color, p: V.PAWN }) - ], - vanish: [ - new PiPo({ x: x, y: y, c: color, p: V.PAWN }), - new PiPo({ x: i - s[0], y: j - s[1], c: oppCol, p: V.PAWN }) - ] - }); - // Is there another capture possible then? - [i, j] = [i + 2*s[0], j + 2*s[1]]; + for (let s of V.steps[V.ROOK]) { + let curmv = new Move({ + appear: [ new PiPo({ x: -1, y: -1, c: color, p: V.PAWN }) ], + vanish: [ new PiPo({ x: x, y: y, c: color, p: V.PAWN }) ] + }); + for (let mult = 2; ; mult += 2) { + let [i, j] = [x + mult * s[0], y + mult * s[1]]; if ( V.OnBoard(i, j) && this.board[i][j] == V.EMPTY && this.board[i - s[0]][j - s[1]] != V.EMPTY && this.getColor(i - s[0], j - s[1]) == oppCol ) { - mv.end.moreCapture = true; + curmv.vanish.push( + new PiPo({ x: i - s[0], y: j - s[1], c: oppCol, p: V.PAWN })); + let mv = JSON.parse(JSON.stringify(curmv)); + mv.appear[0].x = i; + mv.appear[0].y = j; + mv.end = { x: i, y: j }; + moves.push(mv); } - moves.push(mv); + else break; } } return moves; @@ -174,59 +144,14 @@ export class KonaneRules extends ChessRules { return (this.turn == "w" ? "0-1" : "1-0"); } - play(move) { - V.PlayOnBoard(this.board, move); - if (!move.end.moreCapture) { - this.turn = V.GetOppCol(this.turn); - this.movesCount++; - this.captures = []; - } - else { - this.captures.push( - { - start: move.start, - end: { x: move.end.x, y: move.end.y } - } - ); - } - } - - undo(move) { - V.UndoOnBoard(this.board, move); - if (!move.end.moreCapture) { - this.turn = V.GetOppCol(this.turn); - this.movesCount--; - } - else this.captures.pop(); - } - - getComputerMove() { - const color = this.turn; - let mvArray = []; - let mv = null; - const undoAll = () => { - for (let i = mvArray.length - 1; i >= 0; i--) this.undo(mvArray[i]); - }; - // Just play random moves (for now at least. TODO?) - while (this.turn == color) { - let moves = super.getAllValidMoves(); - if (moves.length == 0) { - // Shouldn't happen, but... - undoAll(); - return null; - } - mv = moves[randInt(moves.length)]; - mvArray.push(mv); - this.play(mv); - } - undoAll(); - return (mvArray.length > 1 ? mvArray : mvArray[0]); + static get SEARCH_DEPTH() { + return 4; } getNotation(move) { if (this.movesCount <= 1) return V.CoordsToSquare(move.start) + "X"; if (move.vanish.length == 0) return "end"; - return V.CoordsToSquare(move.start) + "x" + V.CoordsToSquare(move.end); + return V.CoordsToSquare(move.start) + V.CoordsToSquare(move.end); } };