moar bits

This commit is contained in:
mehbark 2025-03-11 16:40:09 -04:00
parent 5ed1748595
commit a71a1af3fb

View file

@ -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 // translate type efficacies to probabilities
// https://github.com/filipekiss/pokemon-type-chart/blob/master/types.json // https://github.com/filipekiss/pokemon-type-chart/blob/master/types.json
@ -70,30 +74,31 @@ struct Args {
#[arg(short, long)] #[arg(short, long)]
output_file: PathBuf, output_file: PathBuf,
#[arg(short, long)] #[arg(short, long)]
steps: u32, steps: u64,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
struct Game { struct Game {
width: i32, width: i64,
height: i32, height: i64,
field: Vec<Type>, field: Vec<Type>,
} }
impl Game { impl Game {
fn new_random(width: u16, height: u16, rng: &mut impl Rng) -> Self { fn new_random(width: u16, height: u16, rng: &mut impl Rng) -> Self {
let (width, height) = (i64::from(width), i64::from(height));
Self { Self {
width: i32::from(width), width,
height: i32::from(height), height,
field: (0..(width * height)).map(|_| rng.random()).collect(), 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) (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) { if self.in_bounds(x, y) {
self.field.get((x + y * self.width) as usize).copied() self.field.get((x + y * self.width) as usize).copied()
} else { } 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) { if self.in_bounds(x, y) {
self.field[(x + y * self.width) as usize] = to; self.field[(x + y * self.width) as usize] = to;
} }
@ -140,7 +145,7 @@ impl Game {
impl From<Game> for ImageBuffer<Rgb<u8>, Vec<u8>> { impl From<Game> for ImageBuffer<Rgb<u8>, Vec<u8>> {
fn from(val: Game) -> Self { fn from(val: Game) -> Self {
ImageBuffer::from_fn(val.width as u32, val.height as u32, |x, y| { 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()
}) })
} }
} }