- let randIndex = 2 * _.random(3);
- let bishop1Pos = positions[randIndex];
- let randIndex_tmp = 2 * _.random(3) + 1;
- let bishop2Pos = positions[randIndex_tmp];
+ let randIndex = _.random(7);
+ const kingPos = positions[randIndex];
+ positions.splice(randIndex, 1);
+
+ // At least a knight must be next to the king:
+ let knight1Pos = undefined;
+ if (kingPos == 0)
+ knight1Pos = 1;
+ else if (kingPos == V.size.y-1)
+ knight1Pos = V.size.y-2;
+ else
+ knight1Pos = kingPos + (Math.random() < 0.5 ? 1 : -1);
+ // Search for knight1Pos index in positions and remove it
+ const knight1Index = positions.indexOf(knight1Pos);
+ positions.splice(knight1Index, 1);
+
+ // King+knight1 are on two consecutive squares: one light, one dark
+ randIndex = 2 * _.random(2);
+ const bishop1Pos = positions[randIndex];
+ let randIndex_tmp = 2 * _.random(2) + 1;
+ const bishop2Pos = positions[randIndex_tmp];