Stash a maybe working mess

This commit is contained in:
2023-03-08 15:08:54 +00:00
parent c707a20a75
commit eceb067add
15 changed files with 60418 additions and 30 deletions
+8 -8
View File
@@ -1,8 +1,8 @@
use rand::Rng;
use crate::system::{GriddedPosition, Position, Storage};
pub trait Sticker<P: Position> {
fn should_stick<R: Rng, S: Storage<P>>(&self, rng: &mut R, space: &S, position: &P) -> bool;
pub trait Sticker<P: Position, S: Storage<P>> {
fn should_stick<R: Rng>(&self, rng: &mut R, space: &S, position: &P) -> bool;
}
pub struct SimpleSticking;
@@ -11,19 +11,19 @@ pub struct ProbabilisticSticking {
pub stick_probability: f32
}
impl<P: GriddedPosition> Sticker<P> for SimpleSticking {
fn should_stick<R: Rng, S: Storage<P>>(&self, rng: &mut R, space: &S, position: &P) -> bool {
impl<P: GriddedPosition, S: Storage<P>> Sticker<P, S> for SimpleSticking {
fn should_stick<R: Rng>(&self, rng: &mut R, space: &S, position: &P) -> bool {
(0..P::NEIGHBOURS)
.map(|n| position.neighbour(n))
.any(|neighbour| space.at(&neighbour))
.any(|neighbour| space.is_occupied(&neighbour))
}
}
impl<P: GriddedPosition> Sticker<P> for ProbabilisticSticking {
fn should_stick<R: Rng, S: Storage<P>>(&self, rng: &mut R, space: &S, position: &P) -> bool {
impl<P: GriddedPosition, S: Storage<P>> Sticker<P, S> for ProbabilisticSticking {
fn should_stick<R: Rng>(&self, rng: &mut R, space: &S, position: &P) -> bool {
(0..P::NEIGHBOURS)
.map(|n| position.neighbour(n))
.any(|neighbour| space.at(&neighbour) && rng.gen_range(0.0f32..=1.0) < self.stick_probability)
.any(|neighbour| space.is_occupied(&neighbour) && rng.gen_range(0.0f32..=1.0) < self.stick_probability)
}
}