X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FMarseille.js;h=ac1782f1af569ab4ff47c3c36cf050300a235982;hb=5fde3a01497262862afc4cb4c9457d4e0ad69a4a;hp=2d4ecfa4207a31f778ccaf7107f0db949bacde7a;hpb=8d61fc4ab7373b4a576f3f9108cdf7768ae27096;p=vchess.git diff --git a/client/src/variants/Marseille.js b/client/src/variants/Marseille.js index 2d4ecfa4..ac1782f1 100644 --- a/client/src/variants/Marseille.js +++ b/client/src/variants/Marseille.js @@ -1,4 +1,7 @@ -class MarseilleRules extends ChessRules +import { ChessRules } from "@/base_rules"; +import { randInt } from "@/utils/alea"; + +export const VariantRules = class MarseilleRules extends ChessRules { static IsGoodEnpassant(enpassant) { @@ -144,12 +147,13 @@ class MarseilleRules extends ChessRules play(move) { move.flags = JSON.stringify(this.aggregateFlags()); - move.turn = this.turn + this.subturn; + move.turn = this.turn + this.subTurn; V.PlayOnBoard(this.board, move); const epSq = this.getEpSquare(move); if (this.subTurn == 0) //first move in game { this.turn = "b"; + this.subTurn = 1; this.epSquares.push([epSq]); } // Does this move give check on subturn 1? If yes, skip subturn 2 @@ -218,23 +222,23 @@ class MarseilleRules extends ChessRules // Search best (half) move for opponent turn const getBestMoveEval = () => { const turnBefore = this.turn + this.subTurn; - let moves = this.getAllValidMoves(); - if (moves.length == 0) + let score = this.getCurrentScore(); + if (score != "*") { - const score = this.checkGameEnd(); if (score == "1/2") return 0; return maxeval * (score == "1-0" ? 1 : -1); } + let moves = this.getAllValidMoves(); let res = (oppCol == "w" ? -maxeval : maxeval); for (let m of moves) { this.play(m); + score = this.getCurrentScore(); // Now turn is oppCol,2 if m doesn't give check // Otherwise it's color,1. In both cases the next test makes sense - if (!this.atLeastOneMove()) + if (score != "*") { - const score = this.checkGameEnd(); if (score == "1/2") res = (oppCol == "w" ? Math.max(res, 0) : Math.min(res, 0)); else @@ -287,7 +291,7 @@ class MarseilleRules extends ChessRules candidates.push(i); } - const selected = doubleMoves[sample(candidates)].moves; + const selected = doubleMoves[randInt(candidates.length)].moves; if (selected.length == 1) return selected[0]; return selected;