feat(grid): implement cell random generation

Prefer filled over empty cells when generating them randomly because it
makes the game more fun.
This commit is contained in:
Mohammed Amar-Bensaber 2024-12-07 18:02:13 +01:00
parent 46e15af8d7
commit 07437890c9
Signed by: renken
GPG key ID: 1F2BB159B645E575
2 changed files with 16 additions and 0 deletions

View file

@ -1,3 +1,5 @@
mod rand;
#[derive(Clone, Default, Debug, PartialEq)]
pub enum Cell {
/// Filled.

14
src/grid/rand.rs Normal file
View file

@ -0,0 +1,14 @@
use crate::grid::Cell;
use rand::distributions::{Distribution, Standard};
use rand::Rng;
impl Distribution<Cell> for Standard {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Cell {
let filled = rng.gen_bool(2. / 3.);
if filled {
Cell::Filled
} else {
Cell::Empty
}
}
}