X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fbase_rules.js;h=b39fe9c457aa51fefad719cae5292e69fa066471;hb=f9c36b2da005b596ad656f4b6cc4e09ef3c656f1;hp=149bb4d22a1eabc5f05aec382c264b80647d822e;hpb=a97bdbda4ecf83645d409b717e36828784d1450d;p=vchess.git diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 149bb4d2..b39fe9c4 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -197,12 +197,13 @@ export const ChessRules = class ChessRules { const move = moveOrSquare; const s = move.start, e = move.end; - // NOTE: next conditions are first for Atomic, and last for Checkered + // NOTE: next conditions are first for Crazyhouse, and last for Checkered + // TODO: Checkered exceptions are too weird and should move in its own file. if ( - move.appear.length > 0 && + move.vanish.length > 0 && Math.abs(s.x - e.x) == 2 && s.y == e.y && - move.appear[0].p == V.PAWN && + move.vanish[0].p == V.PAWN && ["w", "b"].includes(move.appear[0].c) ) { return { @@ -238,11 +239,20 @@ export const ChessRules = class ChessRules { ///////////// // FEN UTILS - // Setup the initial random (assymetric) position - static GenRandInitFen() { + // Setup the initial random (asymmetric) position + static GenRandInitFen(randomness) { + if (randomness == 0) + // Deterministic: + return "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w 0 1111 -"; + let pieces = { w: new Array(8), b: new Array(8) }; - // Shuffle pieces on first and last rank + // Shuffle pieces on first (and last rank if randomness == 2) for (let c of ["w", "b"]) { + if (c == 'b' && randomness == 1) { + pieces['b'] = pieces['w']; + break; + } + let positions = ArrayFun.range(8); // Get random squares for bishops @@ -310,16 +320,24 @@ export const ChessRules = class ChessRules { // Return current fen (game state) getFen() { return ( - this.getBaseFen() + - " " + - this.getTurnFen() + - " " + + this.getBaseFen() + " " + + this.getTurnFen() + " " + this.movesCount + (V.HasFlags ? " " + this.getFlagsFen() : "") + (V.HasEnpassant ? " " + this.getEnpassantFen() : "") ); } + getFenForRepeat() { + // Omit movesCount, only variable allowed to differ + return ( + this.getBaseFen() + "_" + + this.getTurnFen() + + (V.HasFlags ? "_" + this.getFlagsFen() : "") + + (V.HasEnpassant ? "_" + this.getEnpassantFen() : "") + ); + } + // Position part of the FEN string getBaseFen() { let position = ""; @@ -395,14 +413,12 @@ export const ChessRules = class ChessRules { ////////////////// // INITIALIZATION - constructor(fen) { - // In printDiagram() fen isn't supply because only getPpath() is used - if (fen) - this.re_init(fen); - } - // Fen string fully describes the game state - re_init(fen) { + constructor(fen) { + if (!fen) + // In printDiagram() fen isn't supply because only getPpath() is used + // TODO: find a better solution! + return; const fenParsed = V.ParseFen(fen); this.board = V.GetBoard(fenParsed.position); this.turn = fenParsed.turn[0]; //[0] to work with MarseilleRules