X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fbase_rules.js;h=93772b9bd48958442730c768c64dfb35d4b7ee20;hb=7ba4a5bc5b64e19a1e7f26aa232d5c50770d07ad;hp=149bb4d22a1eabc5f05aec382c264b80647d822e;hpb=a97bdbda4ecf83645d409b717e36828784d1450d;p=vchess.git diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 149bb4d2..93772b9b 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -238,11 +238,21 @@ 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) randomness = 2; + 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 @@ -395,14 +405,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