Board class
This commit is contained in:
parent
6ff12cb56a
commit
ab46566693
@ -2,5 +2,12 @@
|
||||
name = "bgtu-ai-1"
|
||||
edition = "2024"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
egui = {registry = "crates-io", version = "0.33.3"}
|
||||
eframe = { version = "0.33.3", default-features = false, features = ["default_fonts", "glow"] }
|
||||
|
||||
[profile.dev.package.eframe]
|
||||
opt-level = 2
|
||||
debug = true
|
||||
42
lab1/src/algo/board.rs
Normal file
42
lab1/src/algo/board.rs
Normal file
@ -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<usize> 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<usize> 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(),
|
||||
};
|
||||
}
|
||||
}
|
||||
1
lab1/src/algo/mod.rs
Normal file
1
lab1/src/algo/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
mod board;
|
||||
@ -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() {
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user