X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=base_rules.js;h=dc25e542dae4629512e3ac0a0a38bc401561913f;hb=dc10e429231932c19da6d1ff2ce98c7a042829ab;hp=01a2c2424816144c19a3ddf7d6c5c7cdeaad4dc4;hpb=9b76053854ec41e9f4d52aa5ddc51ea4c4c33ab6;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 01a2c24..dc25e54 100644 --- a/base_rules.js +++ b/base_rules.js @@ -208,7 +208,7 @@ export default class ChessRules { baseFen.o = Object.assign({init: true}, baseFen.o); const parts = this.getPartFen(baseFen.o); return ( - baseFen.fen + + baseFen.fen + " w 0" + (Object.keys(parts).length > 0 ? (" " + JSON.stringify(parts)) : "") ); } @@ -218,7 +218,7 @@ export default class ChessRules { let fen, flags = "0707"; if (!this.options.randomness) // Deterministic: - fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w 0"; + fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"; else { // Randomize @@ -271,8 +271,7 @@ export default class ChessRules { fen = ( pieces["b"].join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" + - pieces["w"].join("").toUpperCase() + - " w 0" + pieces["w"].join("").toUpperCase() ); } return { fen: fen, o: {flags: flags} }; @@ -477,17 +476,15 @@ export default class ChessRules { } // ordering as in pieces() p,r,n,b,q,k - initReserves(reserveStr) { + initReserves(reserveStr, pieceArray) { + if (!pieceArray) + pieceArray = ['p', 'r', 'n', 'b', 'q', 'k']; const counts = reserveStr.split("").map(c => parseInt(c, 36)); - this.reserve = { w: {}, b: {} }; - const pieceName = ['p', 'r', 'n', 'b', 'q', 'k']; - const L = pieceName.length; - for (let i of ArrayFun.range(2 * L)) { - if (i < L) - this.reserve['w'][pieceName[i]] = counts[i]; - else - this.reserve['b'][pieceName[i-L]] = counts[i]; - } + const L = pieceArray.length; + this.reserve = { + w: ArrayFun.toObject(pieceArray, counts.slice(0, L)), + b: ArrayFun.toObject(pieceArray, counts.slice(L, 2 * L)) + }; } initIspawn(ispawnStr) { @@ -2420,7 +2417,11 @@ export default class ChessRules { } // What is the score ? (Interesting if game is over) - getCurrentScore(move) { + getCurrentScore(move_s) { + const move = move_s[move_s.length - 1]; + // Shortcut in case the score was computed before: + if (move.result) + return move.result; const color = this.turn; const oppCol = C.GetOppCol(color); const kingPos = {