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:
parent
46e15af8d7
commit
07437890c9
2 changed files with 16 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
mod rand;
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug, PartialEq)]
|
#[derive(Clone, Default, Debug, PartialEq)]
|
||||||
pub enum Cell {
|
pub enum Cell {
|
||||||
/// Filled.
|
/// Filled.
|
||||||
|
|
14
src/grid/rand.rs
Normal file
14
src/grid/rand.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue