blob: af8f4fd6f5db8afc976be66d5b8a573bb17a4e7b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
use rand::RngExt;
use crate::sim::cell_sim::sim::{PostUpdateAction, UpdateCtx};
#[inline]
pub fn sim_update(ctx: &mut UpdateCtx) -> PostUpdateAction {
// only allow upward movement some of the time to limit movement speed
if ctx.rng.random_range(0.0..1.0) > 0.8
&& ctx.swap_or_settle(&[(0, -1)]) == PostUpdateAction::None
{
return PostUpdateAction::None;
}
// same for each horizontal direction
if ctx.rng.random_range(0.0..1.0) > 0.8
&& ctx.swap_or_settle(&[(1 - ctx.seqno_parity as i32 * 2, 0)]) == PostUpdateAction::None
{
return PostUpdateAction::None;
}
if ctx.rng.random_range(0.0..1.0) > 0.8 {
return ctx.swap_or_settle(&[(-1 + ctx.seqno_parity as i32 * 2, 0)]);
}
PostUpdateAction::Apply
}
|