X-Git-Url: https://git.auder.net/images/diag_mark.svg?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FMarseille.js;h=ac1782f1af569ab4ff47c3c36cf050300a235982;hb=5fde3a01497262862afc4cb4c9457d4e0ad69a4a;hp=0439ab4d2c61e3de3a01e7385b7f167641730f9f;hpb=0c3fe8a6c3e02af46e0bc646b40c1a0c420f9dcd;p=vchess.git diff --git a/client/src/variants/Marseille.js b/client/src/variants/Marseille.js index 0439ab4d..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 @@ -205,7 +209,6 @@ class MarseilleRules extends ChessRules }; } - // TODO: this is wrong: revise following base_rules.getComputerMove() // No alpha-beta here, just adapted min-max at depth 2(+1) getComputerMove() { @@ -219,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.getCurrentScore(); 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.getCurrentScore(); if (score == "1/2") res = (oppCol == "w" ? Math.max(res, 0) : Math.min(res, 0)); else @@ -288,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;