From ab4656669346d86d09ea39f9472c14a5597c4107 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Thu, 22 Jan 2026 03:17:43 +0300 Subject: [PATCH] Board class --- lab1/Cargo.toml | 9 ++++++++- lab1/src/algo/board.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ lab1/src/algo/mod.rs | 1 + lab1/src/main.rs | 5 ++++- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 lab1/src/algo/board.rs create mode 100644 lab1/src/algo/mod.rs diff --git a/lab1/Cargo.toml b/lab1/Cargo.toml index c1726b3..782b9b3 100644 --- a/lab1/Cargo.toml +++ b/lab1/Cargo.toml @@ -2,5 +2,12 @@ name = "bgtu-ai-1" edition = "2024" +[lints] +workspace = true + [dependencies] -egui = {registry = "crates-io", version = "0.33.3"} \ No newline at end of file +eframe = { version = "0.33.3", default-features = false, features = ["default_fonts", "glow"] } + +[profile.dev.package.eframe] +opt-level = 2 +debug = true \ No newline at end of file diff --git a/lab1/src/algo/board.rs b/lab1/src/algo/board.rs new file mode 100644 index 0000000..7914e21 --- /dev/null +++ b/lab1/src/algo/board.rs @@ -0,0 +1,42 @@ +use std::ops::{Index, IndexMut}; + +pub(crate) struct Board { + data: Box<[usize]>, +} + +impl Board { + pub fn alloc(size: usize) -> Self { + return Self { + data: vec![0usize; size].into_boxed_slice(), + }; + } +} + +impl Index for Board { + type Output = usize; + + fn index(&self, index: usize) -> &Self::Output { + return self + .data + .get(index) + .unwrap_or_else(|| panic!("Y out of bounds: {index} >= {}", self.data.len())); + } +} + +impl IndexMut for Board { + fn index_mut(&mut self, index: usize) -> &mut Self::Output { + let len = self.data.len(); + return self + .data + .get_mut(index) + .unwrap_or_else(|| panic!("Y out of bounds: {index} >= {len}")); + } +} + +impl Clone for Board { + fn clone(&self) -> Self { + return Self { + data: self.data.clone(), + }; + } +} diff --git a/lab1/src/algo/mod.rs b/lab1/src/algo/mod.rs new file mode 100644 index 0000000..1a9bdc2 --- /dev/null +++ b/lab1/src/algo/mod.rs @@ -0,0 +1 @@ +mod board; \ No newline at end of file diff --git a/lab1/src/main.rs b/lab1/src/main.rs index cc0f6c9..e2e9b4a 100644 --- a/lab1/src/main.rs +++ b/lab1/src/main.rs @@ -1,4 +1,7 @@ -mod board; +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release +#![expect(rustdoc::missing_crate_level_docs)] // it's an example + +mod algo; fn main() {