X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FSwap.js;h=3f4cde402b47807b2d4d1a73d0574152600992b9;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=bf4e78715c000b9b0992733db0859edab0c89efb;hpb=964eda04ad6415b4ec95387ea08b63a3d0f0f9cc;p=vchess.git diff --git a/client/src/variants/Swap.js b/client/src/variants/Swap.js index bf4e7871..3f4cde40 100644 --- a/client/src/variants/Swap.js +++ b/client/src/variants/Swap.js @@ -2,6 +2,7 @@ import { ChessRules, PiPo } from "@/base_rules"; import { randInt } from "@/utils/alea"; export class SwapRules extends ChessRules { + setOtherVariables(fen) { super.setOtherVariables(fen); // Local stack of swaps @@ -34,7 +35,7 @@ export class SwapRules extends ChessRules { } getPPpath(m) { - if (m.vanish.length == 1) return super.getPPpath(m); + if (m.appear.length == 1) return super.getPPpath(m); // Swap promotion: return m.appear[1].c + m.appear[1].p; } @@ -71,7 +72,7 @@ export class SwapRules extends ChessRules { const color = this.turn; const piece = this.getPiece(x, y); const addSmoves = (i, j) => { - if (this.getPiece(i, j) != piece) + if (this.getPiece(i, j) != piece || this.getColor(i, j) != color) Array.prototype.push.apply(moves, this.getSwapMoves([x, y], [i, j])); }; switch (piece) { @@ -145,9 +146,9 @@ export class SwapRules extends ChessRules { }); } - static GenRandInitFen(randomness) { + static GenRandInitFen(options) { // Add empty smove: - return ChessRules.GenRandInitFen(randomness) + " -"; + return ChessRules.GenRandInitFen(options) + " -"; } getSmoveFen() { @@ -269,28 +270,8 @@ export class SwapRules extends ChessRules { const color = this.turn; const oppCol = V.GetOppCol(this.turn); - // Search best (half) move for opponent turn (TODO: a bit too slow) -// const getBestMoveEval = () => { -// let score = this.getCurrentScore(); -// if (score != "*") 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 allow a swap and movesCount >= 2 -// // Otherwise it's color,1. In both cases the next test makes sense -// if (score != "*") { -// // Game over -// this.undo(m); -// return maxeval * (score == "1-0" ? 1 : -1); -// } -// const evalPos = this.evalPosition(); -// res = oppCol == "w" ? Math.max(res, evalPos) : Math.min(res, evalPos); -// this.undo(m); -// } -// return res; -// }; + // NOTE: searching best (half) move for opponent turn is a bit too slow. + // => Only 2 half moves depth here. const moves11 = this.getAllValidMoves(); if (this.movesCount == 0) @@ -311,7 +292,6 @@ export class SwapRules extends ChessRules { let moves12 = this.getAllValidMoves(); for (let j = 0; j < moves12.length; j++) { this.play(moves12[j]); -// const evalMove = getBestMoveEval() + 0.05 - Math.random() / 10; const evalMove = this.evalPosition() + 0.05 - Math.random() / 10; if ( !bestMove || @@ -341,4 +321,5 @@ export class SwapRules extends ChessRules { // Swap return "S" + V.CoordsToSquare(move.start) + V.CoordsToSquare(move.end); } + };