dont work homework

This commit is contained in:
lemon-cat committed 2026-05-18 14:42:41 +03:00
1 parent 1e9529733f
commit 6ffbfbb7bf
5 files changed
+238 -1

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
use std::clone;
use rand::Rng;
#[derive(Clone)]
pub struct Grid {
grd: Vec<bool>,
rez: (usize, usize),
}
impl Grid {
pub fn init(r: &(usize, usize)) -> Self {
Grid {
grd: vec![false; r.0 * r.1],
rez: r.clone(),
}
}
pub fn push_in(&mut self, p: bool, pos: &(usize, usize)) {
self.grd[pos.1 * self.rez.0 + pos.0] = p;
}
pub fn who_in(&self, pos: &(usize, usize)) -> bool {
return self.grd[pos.1 * self.rez.0 + pos.0] == true;
}
pub fn rand(&mut self) {
let mut rng = rand::thread_rng();
for i in 0..self.rez.0 {
for j in 0..self.rez.1 {
let mut r = rng.gen_range(0..=1) == 0;
self.push_in(r, &(i, j));
}
}
}
}