a[j] = x;
}
}
+function expandAndShuffleBag(bag, factor) {
+ let newBag = [];
+ while (factor >= 1) {
+ newBag = newBag.concat(bag);
+ factor--;
+ }
+ if (Math.round(bag.length * factor) > 0) {
+ let shuffleBag = bag.slice ();
+ shuffleInPlace(shuffleBag);
+ newBag = newBag.concat(shuffleBag.slice(0, Math.round(shuffleBag.length * factor)));
+ }
+ shuffleInPlace(newBag);
+ return (newBag);
+}
function Game() {
this.init();
this.lastUpdated = new Date();
this.currentPlayer = "";
- factor = this.factor;
- this.bag = [];
- while (factor > 1) {
- this.bag = this.bag.concat(bag.slice());
- factor--;
- }
- if (Math.round(bag.length * factor) > 0) {
- shuffleInPlace(bag);
- this.bag = this.bag.concat(bag.slice(0, Math.round(bag.length * factor)));
- }
- shuffleInPlace(this.bag);
+ this.bag = expandAndShuffleBag(bag, this.factor);
};
Game.prototype.toJSON = function () {
game.factor = obj.factor || DEFAULT_BAG_FACTOR;
game.board = obj.board || newBoard(game.label);
game.lang = obj.lang || DEFAULT_BOARD_LANG;
- game.bag = boardTilesPerLang[game.lang].bag.slice();
+ game.bag = obj.bag || expandAndShuffleBag(boardTilesPerLang[game.lang].bag.slice(), game.factor);
game.letterValues = boardTilesPerLang[game.lang].letterValues;
game.racks = obj.racks || {};
game.scores = obj.scores || {};