use rand::distributions::{Distribution, Standard};
use crate::battleship::constants::{NUM_COLS, NUM_ROWS};
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Pos {
pub x: usize,
pub y: usize
}
impl Pos {
#[doc(hidden)]
pub fn new(x: usize, y: usize) -> Self {
Self {
x, y
}
}
}
impl Distribution<Pos> for Standard {
fn sample<R: rand::prelude::Rng + ?Sized>(&self, rng: &mut R) -> Pos {
Pos::new(
rng.gen_range(0..NUM_COLS),
rng.gen_range(0..NUM_ROWS)
)
}
}
#[macro_export]
macro_rules! pos {
($x:expr, $y:expr) => {
Pos::new($x, $y)
};
}