/// Generates a new board with the given width, height, mine count and seed.
///
/// # Panics
/// If `mines >= width * height`.
Generates a new board with the given width, height, mine count and seed.
Generates a new board with the given width height mine count and seed .
pub fn new(settings: &GenerationSettings) -> Self {
        let size = settings.width * settings.height;
        assert!(
            settings.mine_count < size,
            "`mines` must be less than `size`"
        );
        // Generate mine indexes using config seed.
        let mut rng = rand_pcg::Pcg64Mcg::new(settings.to_state_seed());
        let mine_idxs = rand::seq::index::sample(&mut rng, size, settings.mine_count);
        // Setup empty board with the final size.
        let mut board = Self {
            tiles: vec![Tile::default(); size],
            width: settings.width,
        };
        // Add mines and number tiles based on mine positions.
        mine_idxs.iter().for_each(|idx| {
            board.tiles[idx] = Tile::with_value(Value::Mine);
            // Increment number of all non-mine neighbors.
            Position::from_index(idx, settings.width)
                .neighbors(settings.width, settings.height)
                .for_each(|pos| {
                    // Unwrap as these positions are directly from enumeration.
                    board.get_tile_mut(pos).unwrap().increment_value();
                });
        });
        board
    }
pub fn new ( settings : & GenerationSettings ) -> Self { let size = settings . width * settings . height ; assert ! ( settings mine_count size " " ) ; // Generate mine indexes using config seed. let mut rng = rand_pcg :: Pcg64Mcg :: new ( settings . to_state_seed ( ) ) ; let mine_idxs = rand :: seq :: index :: sample ( & mut rng , size , settings . mine_count ) ; // Setup empty board with the final size. let mut board = Self { tiles : vec ! [ Tile default ( ) size ] , width : settings . width , } ; // Add mines and number tiles based on mine positions. mine_idxs . iter ( ) . for_each ( | idx | { board . tiles [ idx ] = Tile :: with_value ( Value :: Mine ) ; // Increment number of all non-mine neighbors. Position :: from_index ( idx , settings . width ) . neighbors ( settings . width , settings . height ) . for_each ( | pos | { // Unwrap as these positions are directly from enumeration. board . get_tile_mut ( pos ) . unwrap ( ) . increment_value ( ) ; } ) ; } ) ; board }
Generates a new board with the given width, height, mine count and seed.
Generates a new board with the given width height mine count and seed .
settings
&GenerationSettings
panics
If `mines >= width * height`.
If ` mines > = width * height ` .