From a71a1af3fb8fff3543c34557ded6733df362f2f8 Mon Sep 17 00:00:00 2001 From: mehbark <terezi@pyrope.net> Date: Tue, 11 Mar 2025 16:40:09 -0400 Subject: [PATCH] moar bits --- src/main.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index c693942..09073c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,8 @@ -#![allow(clippy::cast_sign_loss, clippy::cast_possible_wrap)] +#![allow( + clippy::cast_sign_loss, + clippy::cast_possible_wrap, + clippy::cast_possible_truncation +)] // translate type efficacies to probabilities // https://github.com/filipekiss/pokemon-type-chart/blob/master/types.json @@ -70,30 +74,31 @@ struct Args { #[arg(short, long)] output_file: PathBuf, #[arg(short, long)] - steps: u32, + steps: u64, } #[derive(Debug, Clone)] struct Game { - width: i32, - height: i32, + width: i64, + height: i64, field: Vec<Type>, } impl Game { fn new_random(width: u16, height: u16, rng: &mut impl Rng) -> Self { + let (width, height) = (i64::from(width), i64::from(height)); Self { - width: i32::from(width), - height: i32::from(height), + width, + height, field: (0..(width * height)).map(|_| rng.random()).collect(), } } - fn in_bounds(&self, x: i32, y: i32) -> bool { + fn in_bounds(&self, x: i64, y: i64) -> bool { (0..self.width).contains(&x) && (0..self.height).contains(&y) } - fn at(&self, x: i32, y: i32) -> Option<Type> { + fn at(&self, x: i64, y: i64) -> Option<Type> { if self.in_bounds(x, y) { self.field.get((x + y * self.width) as usize).copied() } else { @@ -101,7 +106,7 @@ impl Game { } } - fn set(&mut self, x: i32, y: i32, to: Type) { + fn set(&mut self, x: i64, y: i64, to: Type) { if self.in_bounds(x, y) { self.field[(x + y * self.width) as usize] = to; } @@ -140,7 +145,7 @@ impl Game { impl From<Game> for ImageBuffer<Rgb<u8>, Vec<u8>> { fn from(val: Game) -> Self { ImageBuffer::from_fn(val.width as u32, val.height as u32, |x, y| { - val.at(x as i32, y as i32).unwrap().color() + val.at(i64::from(x), i64::from(y)).unwrap().color() }) } }