tidepool: seed from u64

This commit is contained in:
tali 2023-04-11 20:03:54 -04:00
parent a0aaba461d
commit 68cb2cae58
2 changed files with 7 additions and 21 deletions

View File

@ -1,35 +1,21 @@
use fish::bot::Bot;
use mino::srs::Queue;
use rand::Rng as _;
use rand::RngCore as _;
use tidepool::sim;
struct RngSeed([u8; 32]);
impl rand::distributions::Distribution<RngSeed> for rand::distributions::Standard {
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> RngSeed {
RngSeed(self.sample(rng))
}
}
impl std::fmt::Display for RngSeed {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.iter().try_for_each(|&b| write!(f, "{b:02x}"))
}
}
pub fn main() -> std::io::Result<()> {
const THINK_CYCLES: usize = 5_000;
const GOAL: usize = 100;
const GOAL: usize = 18;
tracing_subscriber::fmt::fmt()
.with_writer(std::io::stderr)
.with_env_filter(tracing_subscriber::filter::EnvFilter::from_default_env())
.init();
let seed = rand::thread_rng().gen::<RngSeed>();
let seed = rand::thread_rng().next_u64();
println!("using seed: {seed}");
let mut sim = sim::Simul::new(seed.0, sim::Options::jstris(GOAL));
let mut sim = sim::Simul::new(seed, sim::Options::jstris(GOAL));
let mut ds = 0;
let mut ps = 0;

View File

@ -3,7 +3,7 @@ use crate::queue::Queue;
use mino::matrix::{Mat, MatBuf};
use mino::srs::{Piece, PieceType};
use rand::SeedableRng as _;
use rand::SeedableRng;
use std::ops::RangeInclusive;
pub struct Options {
@ -35,8 +35,8 @@ pub struct Simul {
}
impl Simul {
pub fn new(seed: [u8; 32], options: Options) -> Self {
let rng1 = Rng::from_seed(seed);
pub fn new(seed: u64, options: Options) -> Self {
let rng1 = Rng::seed_from_u64(seed);
let mut rng2 = rng1.clone();
rng2.jump();