X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FHidden.js;h=24b8dd04a61d3f1231bba9b3e4297f2c9b298293;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=79c3dfbdd2c29aefba4933f315271188f6b413e3;hpb=3a2a7b5fd3c6bfd0752838094c27e1fb6172d109;p=vchess.git diff --git a/client/src/variants/Hidden.js b/client/src/variants/Hidden.js index 79c3dfbd..24b8dd04 100644 --- a/client/src/variants/Hidden.js +++ b/client/src/variants/Hidden.js @@ -2,7 +2,13 @@ import { ChessRules, PiPo, Move } from "@/base_rules"; import { ArrayFun } from "@/utils/array"; import { randInt } from "@/utils/alea"; -export const VariantRules = class HiddenRules extends ChessRules { +export class HiddenRules extends ChessRules { + + static get Options() { + // TODO: later, option "free placement" + return null; + } + static get HasFlags() { return false; } @@ -11,6 +17,10 @@ export const VariantRules = class HiddenRules extends ChessRules { return false; } + static get SomeHiddenMoves() { + return true; + } + // Analyse in Hidden mode makes no sense static get CanAnalyze() { return false; @@ -50,7 +60,7 @@ export const VariantRules = class HiddenRules extends ChessRules { } static get PIECES() { - return ChessRules.PIECES.concat(Object.values(V.HIDDEN_CODE)); + return ChessRules.PIECES.concat(Object.keys(V.HIDDEN_DECODE)); } // Pieces can be hidden :) @@ -90,7 +100,7 @@ export const VariantRules = class HiddenRules extends ChessRules { this.kingPos["w"] = [i, k]; break; default: { - const num = parseInt(fenRows[i].charAt(j)); + const num = parseInt(fenRows[i].charAt(j), 10); if (!isNaN(num)) k += num - 1; } } @@ -143,16 +153,6 @@ export const VariantRules = class HiddenRules extends ChessRules { return mv; } - // What are the king moves from square x,y ? - getPotentialKingMoves(sq) { - // No castling: - return this.getSlideNJumpMoves( - sq, - V.steps[V.ROOK].concat(V.steps[V.BISHOP]), - "oneStep" - ); - } - filterValid(moves) { return moves; } @@ -215,9 +215,11 @@ export const VariantRules = class HiddenRules extends ChessRules { pieces[c][rook2Pos] = "u"; } let upFen = pieces["b"].join(""); - upFen = upFen.substr(0,8) + "/" + upFen.substr(8).split("").reverse().join(""); + upFen = upFen.substr(0,8) + "/" + + upFen.substr(8).split("").reverse().join(""); let downFen = pieces["b"].join("").toUpperCase(); - downFen = downFen.substr(0,8) + "/" + downFen.substr(8).split("").reverse().join(""); + downFen = downFen.substr(0,8) + "/" + + downFen.substr(8).split("").reverse().join(""); return upFen + "/8/8/8/8/" + downFen + " w 0"; } @@ -265,9 +267,10 @@ export const VariantRules = class HiddenRules extends ChessRules { if (move.vanish.length == 2 && move.vanish[1].c != color) { // OK this isn't a castling move const myPieceVal = V.VALUES[move.appear[0].p]; - const hisPieceVal = Object.keys(V.HIDDEN_DECODE).includes(move.vanish[1].p) - ? undefined - : V.VALUES[move.vanish[1].p]; + const hisPieceVal = + Object.keys(V.HIDDEN_DECODE).includes(move.vanish[1].p) + ? undefined + : V.VALUES[move.vanish[1].p]; if (!hisPieceVal) { // Opponent's piece is unknown: do not take too much risk move.eval = -myPieceVal + 1.5; //so that pawns always take @@ -286,7 +289,8 @@ export const VariantRules = class HiddenRules extends ChessRules { // If no capture, favor small step moves, // but sometimes move the knight anyway const penalty = V.Decode(move.vanish[0].p) != V.KNIGHT - ? Math.abs(move.end.x - move.start.x) + Math.abs(move.end.y - move.start.y) + ? Math.abs(move.end.x - move.start.x) + + Math.abs(move.end.y - move.start.y) : (Math.random() < 0.5 ? 3 : 1); move.eval -= penalty / (V.size.x + V.size.y - 1); } @@ -329,4 +333,5 @@ export const VariantRules = class HiddenRules extends ChessRules { finalSquare ); } + };