+ static GenRandInitFen(options) {
+ if (options.randomness == 0) {
+ return (
+ "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL " +
+ "w 0 00000000000000"
+ );
+ }
+ // Randomization following these indications:
+ // http://www.shogi.net/shogi-l/Archive/2007/Nmar16-02.txt
+ let pieces1 = { w: new Array(4), b: new Array(4) };
+ let positions2 = { w: new Array(2), b: new Array(2) };
+ for (let c of ["w", "b"]) {
+ if (c == 'b' && options.randomness == 1) {
+ pieces1['b'] = JSON.parse(JSON.stringify(pieces1['w'])).reverse();
+ positions2['b'] =
+ JSON.parse(JSON.stringify(positions2['w'])).reverse()
+ .map(p => 8 - p);
+ break;
+ }
+ let positions = shuffle(ArrayFun.range(4));
+ const composition = ['s', 's', 'g', 'g'];
+ for (let i = 0; i < 4; i++) pieces1[c][positions[i]] = composition[i];
+ positions2[c] = sample(ArrayFun.range(9), 2).sort();
+ }