// builds all the tiles and assigns bombs to them private void PlaceMines(int firstIndex) { //long start = DateTime.Now.Ticks; // hold the tiles to exclude from being a mine HashSet <int> excludedIndices = new HashSet <int>(); excludedIndices.Add(firstIndex); // for a zero start game all the adjacent tile can't be mines either if (this.description.gameType == GameType.Zero) { foreach (int adjIndex in GetAdjacentIndex(firstIndex)) { excludedIndices.Add(adjIndex); } } // create a list of all included indices List <int> indices = new List <int>(); for (int y = 0; y < this.description.height; y++) { for (int x = 0; x < this.description.width; x++) { int i = GetIndex(x, y); if (!excludedIndices.Contains(i)) { indices.Add(i); } } } // shuffle the indices using a seed indices.Shuffle(seed); // allocate the mines and calculate the values for (int i = 0; i < description.mines; i++) { int index = indices[i]; MinesweeperTile tile = tiles[index]; //Utility.Write("Setting " + tile.AsText() + " to be a mine"); tile.SetMine(true); // this is set to be a mine // set each affected tile to have an increased 'value' foreach (int adjIndex in GetAdjacentIndex(tile.GetIndex())) { tiles[adjIndex].IncrementValue(); } } this.gameStatus = GameStatus.InPlay; //Write("Ticks to place mines on MinesweeperTiles " + (DateTime.Now.Ticks - start)); }