change PRNG to SplitMix64, add test to monitor determinism
This commit is contained in:
parent
05e6bc3e50
commit
1c8af44523
|
@ -13,7 +13,7 @@ pub struct Options {
|
|||
pub previews: usize,
|
||||
}
|
||||
|
||||
type Rng = rand_xoshiro::Xoshiro256StarStar;
|
||||
pub type Rng = rand_xoshiro::SplitMix64;
|
||||
|
||||
pub struct Simul {
|
||||
queue: Queue,
|
||||
|
@ -25,8 +25,7 @@ pub struct Simul {
|
|||
impl Simul {
|
||||
pub fn new(seed: u64, options: Options) -> Self {
|
||||
let rng1 = Rng::seed_from_u64(seed);
|
||||
let mut rng2 = rng1.clone();
|
||||
rng2.jump();
|
||||
let rng2 = rng1.clone();
|
||||
|
||||
let queue = Queue::new(rng1, options.previews);
|
||||
let mut garbage = Garbage::new(rng2, options.goal, options.garbage);
|
||||
|
@ -256,8 +255,10 @@ mod tests {
|
|||
use super::*;
|
||||
use mino::mat;
|
||||
|
||||
const TEST_SEED: u64 = 0x1234567800ABCDEF;
|
||||
|
||||
fn make_rng() -> Rng {
|
||||
Rng::seed_from_u64(0x1234_5678_00ab_cdef)
|
||||
Rng::seed_from_u64(TEST_SEED)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -422,4 +423,34 @@ mod tests {
|
|||
assert_eq!(garbage.insert(&mut mat, false), 0);
|
||||
assert_eq!(mat.rows(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_deterministic() {
|
||||
let sim = Simul::new(
|
||||
TEST_SEED,
|
||||
Options {
|
||||
goal: 100,
|
||||
garbage: 0..=9,
|
||||
previews: 7,
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
sim.matrix(),
|
||||
mat! {
|
||||
"xxx.xxxxxx";
|
||||
"xxxxx.xxxx";
|
||||
".xxxxxxxxx";
|
||||
"xxx.xxxxxx";
|
||||
"x.xxxxxxxx";
|
||||
".xxxxxxxxx";
|
||||
"xxxxxxxxx.";
|
||||
"xxxx.xxxxx";
|
||||
".xxxxxxxxx";
|
||||
},
|
||||
);
|
||||
assert_eq!(sim.queue().1, {
|
||||
use PieceType::*;
|
||||
vec![J, L, T, Z, S, O, I]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue