2048年新瓷砖的概率分布是多少?

时间:2014-04-06 09:46:14

标签: 2d-games probability-density

这个问题是关于热门游戏2048。我想知道每个转弯处新瓷砖外观的细节:

  • 是50%两倍和50%四肢?
  • 外观概率是否均匀分布在所有空闲位置上?

1 个答案:

答案 0 :(得分:2)

https://github.com/gabrielecirulli/2048/blob/master/js/game_manager.js#L72

// Adds a tile in a random position
GameManager.prototype.addRandomTile = function () {
  if (this.grid.cellsAvailable()) {
    var value = Math.random() < 0.9 ? 2 : 4;
    var tile = new Tile(this.grid.randomAvailableCell(), value);

    this.grid.insertTile(tile);
  }
};

https://github.com/gabrielecirulli/2048/blob/master/js/grid.js#L36

// Find the first available random position
Grid.prototype.randomAvailableCell = function () {
  var cells = this.availableCells();

  if (cells.length) {
    return cells[Math.floor(Math.random() * cells.length)];
  }
};