From 7a3f2592ec89634984ed8669310a3cbd27589479 Mon Sep 17 00:00:00 2001 From: YoEnte Date: Thu, 3 Dec 2026 20:45:06 +0100 Subject: [PATCH] remove plugin folder --- src/plugin2026/board.rs | 122 ------------------ src/plugin2026/errors.rs | 3 - src/plugin2026/field_type.rs | 78 ------------ src/plugin2026/game_state.rs | 119 ------------------ src/plugin2026/move.rs | 41 ------ src/plugin2026/rules_engine.rs | 167 ------------------------- src/plugin2026/test/board_test.rs | 104 --------------- src/plugin2026/test/common.rs | 42 ------- src/plugin2026/test/game_state_test.rs | 87 ------------- src/plugin2026/test/mod.rs | 6 - src/plugin2026/utils.rs | 5 - src/plugin2026/utils/constants.rs | 12 -- src/plugin2026/utils/coordinate.rs | 54 -------- src/plugin2026/utils/direction.rs | 97 -------------- src/plugin2026/utils/team.rs | 41 ------ src/plugin2026/utils/vector.rs | 66 ---------- 16 files changed, 1044 deletions(-) delete mode 100644 src/plugin2026/board.rs delete mode 100644 src/plugin2026/errors.rs delete mode 100644 src/plugin2026/field_type.rs delete mode 100644 src/plugin2026/game_state.rs delete mode 100644 src/plugin2026/move.rs delete mode 100644 src/plugin2026/rules_engine.rs delete mode 100644 src/plugin2026/test/board_test.rs delete mode 100644 src/plugin2026/test/common.rs delete mode 100644 src/plugin2026/test/game_state_test.rs delete mode 100644 src/plugin2026/test/mod.rs delete mode 100644 src/plugin2026/utils.rs delete mode 100644 src/plugin2026/utils/constants.rs delete mode 100644 src/plugin2026/utils/coordinate.rs delete mode 100644 src/plugin2026/utils/direction.rs delete mode 100644 src/plugin2026/utils/team.rs delete mode 100644 src/plugin2026/utils/vector.rs diff --git a/src/plugin2026/board.rs b/src/plugin2026/board.rs deleted file mode 100644 index e0846f5..0000000 --- a/src/plugin2026/board.rs +++ /dev/null @@ -1,122 +0,0 @@ -use pyo3::*; - -use crate::plugin2026::{ - field_type::FieldType, - utils::{ - constants::PluginConstants, - coordinate::Coordinate, - direction::Direction - } -}; - -#[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Board { - #[pyo3(get, set)] - pub map: Vec>, -} - -#[pymethods] -impl Board { - #[new] - pub fn new(map: Vec>) -> Self { - Self { map } - } - - fn __str__(&self) -> String {self.to_string()} - fn __repr__(&self) -> String {format!("{:?}", self)} - fn __eq__(&self, other: &Board) -> bool {self == other} - fn __ne__(&self, other: &Board) -> bool {self != other} - fn deepcopy(&self) -> Board {self.clone()} - - pub fn get_field(&self, position: &Coordinate) -> Option { - - let x = usize::try_from(position.x).ok()?; - let y = usize::try_from(position.y).ok()?; - - self.map - .get(y)? - .get(x) - .cloned() - } - - pub fn get_fields_by_type(&self, field: FieldType) -> Vec { - - let mut positions: Vec = vec![]; - - for (y, row) in self.map.iter().enumerate() { - for (x, f) in row.iter().enumerate() { - if *f == field { - positions.push(Coordinate {x: x as isize, y: y as isize}); - } - } - } - - positions - } - - pub fn get_fields_in_direction(&self, position: &Coordinate, direction: &Direction) -> Vec { - - let mut fields: Vec = Vec::new(); - - for scalar in 1..PluginConstants::BOARD_WIDTH { - let new_pos = position.add_vector(&direction.to_vector().scale(scalar as isize)); - if let Some(field) = self.get_field(&new_pos) { - fields.push(field); - } else {break} - } - - fields - } - - pub fn get_fields_on_line(&self, position: &Coordinate, direction: &Direction) -> Vec { - - let mut fields: Vec = Vec::new(); - - if let Some(field) = self.get_field(position) { - fields.push(field); - } else {return fields} - - let in_dir = self.get_fields_in_direction(position, direction); - let in_mirror = self.get_fields_in_direction(position, &direction.to_mirrored()); - - // merge vecs - for f in in_dir { - fields.push(f); - } - - for f in in_mirror { - fields.insert(0, f); - } - - fields - } - - pub fn get_fish_on_line(&self, position: &Coordinate, direction: &Direction) -> Vec { - - let fields_on_line = self.get_fields_on_line(position, direction); - - let fish_only: Vec = fields_on_line.iter() - .filter(|&f| matches!(f, - FieldType::OneS | FieldType::OneM | FieldType::OneL | - FieldType::TwoS | FieldType::TwoM | FieldType::TwoL - )) - .cloned() - .collect(); - - fish_only - } -} - -impl std::fmt::Display for Board { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f)?; - for row in self.map.iter().rev() { - for field in row { - write!(f, "{} ", *field)?; - } - writeln!(f)?; - } - Ok(()) - } -} diff --git a/src/plugin2026/errors.rs b/src/plugin2026/errors.rs deleted file mode 100644 index 5d09acd..0000000 --- a/src/plugin2026/errors.rs +++ /dev/null @@ -1,3 +0,0 @@ -use pyo3::{exceptions::PyException, *}; - -create_exception!(_socha, PiranhasError, PyException); \ No newline at end of file diff --git a/src/plugin2026/field_type.rs b/src/plugin2026/field_type.rs deleted file mode 100644 index d9bc525..0000000 --- a/src/plugin2026/field_type.rs +++ /dev/null @@ -1,78 +0,0 @@ -use pyo3::*; - -use crate::plugin2026::utils::team::TeamEnum; - -#[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum FieldType { - OneS, - OneM, - OneL, - TwoS, - TwoM, - TwoL, - Squid, - Empty -} - -#[pymethods] -impl FieldType { - fn __str__(&self) -> String {self.to_string()} - fn __repr__(&self) -> String {format!("{:?}", self)} - fn __eq__(&self, other: &FieldType) -> bool {self == other} - fn __ne__(&self, other: &FieldType) -> bool {self != other} - - pub fn get_value(&self) -> usize { - match self { - FieldType::OneS => 1, - FieldType::OneM => 2, - FieldType::OneL => 3, - FieldType::TwoS => 1, - FieldType::TwoM => 2, - FieldType::TwoL => 3, - FieldType::Squid => 0, - FieldType::Empty => 0, - } - } - - pub fn get_team(&self) -> Option { - match self { - FieldType::OneS => Some(TeamEnum::One), - FieldType::OneM => Some(TeamEnum::One), - FieldType::OneL => Some(TeamEnum::One), - FieldType::TwoS => Some(TeamEnum::Two), - FieldType::TwoM => Some(TeamEnum::Two), - FieldType::TwoL => Some(TeamEnum::Two), - _ => None - } - } - - #[staticmethod] - pub fn all_field_types() -> Vec { - vec![ - FieldType::OneS, - FieldType::OneM, - FieldType::OneL, - FieldType::TwoS, - FieldType::TwoM, - FieldType::TwoL, - FieldType::Squid, - FieldType::Empty - ] - } -} - -impl std::fmt::Display for FieldType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::OneS => write!(f, "O1"), - Self::OneM => write!(f, "O2"), - Self::OneL => write!(f, "O3"), - Self::TwoS => write!(f, "T1"), - Self::TwoM => write!(f, "T2"), - Self::TwoL => write!(f, "T3"), - Self::Squid => write!(f, "SQ"), - Self::Empty => write!(f, "--"), - } - } -} \ No newline at end of file diff --git a/src/plugin2026/game_state.rs b/src/plugin2026/game_state.rs deleted file mode 100644 index 1b2bc0a..0000000 --- a/src/plugin2026/game_state.rs +++ /dev/null @@ -1,119 +0,0 @@ -use pyo3::*; - -use crate::plugin2026::{ - board::Board, errors::PiranhasError, field_type::FieldType, r#move::Move, rules_engine::RulesEngine, utils::{ - coordinate::Coordinate, - direction::Direction - } -}; - -#[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct GameState { - #[pyo3(get, set)] - pub board: Board, - #[pyo3(get, set)] - pub turn: usize, - #[pyo3(get, set)] - pub last_move: Option -} - -#[pymethods] -impl GameState { - #[new] - pub fn new(board: Board, turn: usize, last_move: Option) -> Self { - Self { - board, - turn, - last_move, - } - } - - fn __str__(&self) -> String {self.to_string()} - fn __repr__(&self) -> String {format!("{:?}", self)} - fn __eq__(&self, other: &GameState) -> bool {self == other} - fn __ne__(&self, other: &GameState) -> bool {self != other} - fn deepcopy(&self) -> GameState {self.clone()} - - pub fn set_board_field(&mut self, position: &Coordinate, field: FieldType) -> Result<(), PyErr> { - let x = position.x as usize; - let y = position.y as usize; - - if y >= self.board.map.len() || x >= self.board.map[0].len() { - return Err(PiranhasError::new_err("Position not in bounds of map")); - } - - self.board.map[y][x] = field; - - Ok(()) - } - - pub fn possible_moves_for(&self, start: &Coordinate) -> Vec { - let mut moves: Vec = Vec::new(); - - for d in Direction::all_directions() { - moves.push(Move { start: start.to_owned(), direction: d }); - } - - moves - .into_iter() - .filter(|m| RulesEngine::can_execute_move(&self.board, m).is_ok()) - .collect() - } - - pub fn possible_moves(&self) -> Vec { - let mut moves: Vec = Vec::new(); - let mut fish: Vec = Vec::new(); - - for f in RulesEngine::get_team_on_turn(self.turn).get_fish_types() { - fish.append(&mut self.board.get_fields_by_type(f)); - } - - for f in fish { - moves.extend(self.possible_moves_for(&f)); - } - - moves - } - - pub fn perform_move(&self, move_: &Move) -> Result { - - let mut new_game_state = self.clone(); - new_game_state.perform_move_mut(move_)?; - - Ok(new_game_state) - } - - pub fn perform_move_mut(&mut self, move_: &Move) -> Result<(), PyErr> { - - RulesEngine::can_execute_move(&self.board, move_) - .map_err(|e| { - let full_error = e.to_string(); - let clean_error = full_error.strip_prefix("PiranhasError:").unwrap_or(&full_error).trim(); - PiranhasError::new_err(format!("Cannot execute move: {}", clean_error)) - })?; - - let target = RulesEngine::target_position(&self.board, move_); - let mut new_board = self.board.clone(); - new_board.map[target.y as usize][target.x as usize] = self.board.get_field(&move_.start).unwrap(); - new_board.map[move_.start.y as usize][move_.start.x as usize] = FieldType::Empty; - - self.board = new_board; - self.turn += 1; - self.last_move = Some(move_.clone()); - - Ok(()) - } -} - -impl std::fmt::Display for GameState { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "Zug: {}\nSpielbrett:{}Letzter Zug: {:?}", - self.turn, - self.board, - self.last_move - ) - } -} \ No newline at end of file diff --git a/src/plugin2026/move.rs b/src/plugin2026/move.rs deleted file mode 100644 index 8618753..0000000 --- a/src/plugin2026/move.rs +++ /dev/null @@ -1,41 +0,0 @@ -use std::fmt::Debug; - -use pyo3::*; - -use crate::plugin2026::{ - utils::{ - coordinate::Coordinate, - direction::Direction - } -}; - -#[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Move { - #[pyo3(get, set)] - pub start: Coordinate, - #[pyo3(get, set)] - pub direction: Direction -} - -#[pymethods] -impl Move { - #[new] - pub fn new(start: Coordinate, direction: Direction) -> Self { - Self { - start, direction - } - } - - fn __str__(&self) -> String {self.to_string()} - fn __repr__(&self) -> String {format!("{:?}", self)} - fn __eq__(&self, other: &Move) -> bool {self == other} - fn __ne__(&self, other: &Move) -> bool {self != other} - fn deepcopy(&self) -> Move {self.clone()} -} - -impl std::fmt::Display for Move { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "Move von {} in Richtung {}", self.start, self.direction) - } -} diff --git a/src/plugin2026/rules_engine.rs b/src/plugin2026/rules_engine.rs deleted file mode 100644 index bc3fa62..0000000 --- a/src/plugin2026/rules_engine.rs +++ /dev/null @@ -1,167 +0,0 @@ -use std::vec; - -use pyo3::*; - -use crate::plugin2026::{ - board::Board, errors::PiranhasError, field_type::FieldType, r#move::Move, - utils::{ - constants::PluginConstants, - coordinate::Coordinate, - direction::Direction, - team::TeamEnum - } -}; - -#[pyclass] -pub struct RulesEngine; - -#[pymethods] -impl RulesEngine { - - #[staticmethod] - pub fn move_distance(board: &Board, move_: &Move) -> usize { - board.get_fish_on_line(&move_.start, &move_.direction).len() - } - - #[staticmethod] - pub fn target_position(board: &Board, move_: &Move) -> Coordinate { - move_.start.clone().add_vector(&move_.direction.to_vector().scale(Self::move_distance(board, move_) as isize)) - } - - #[staticmethod] - pub fn is_in_bounds(coordinate: &Coordinate) -> bool { - coordinate.x >= 0 && coordinate.x < PluginConstants::BOARD_WIDTH as isize - && coordinate.y >= 0 && coordinate.y < PluginConstants::BOARD_HEIGHT as isize - } - - #[staticmethod] - pub fn can_execute_move(board: &Board, move_: &Move) -> Result<(), PyErr> { - - let target_pos = Self::target_position(board, move_); - - Self::is_in_bounds(&move_.start) - .then_some(()) - .ok_or_else(|| PiranhasError::new_err("Start position is out of bounds"))?; - - Self::is_in_bounds(&target_pos) - .then_some(()) - .ok_or_else(|| PiranhasError::new_err("Target position is out of bounds"))?; - - let start_field = board.get_field(&move_.start) - .expect("Already validated in-bounds position"); - let target_field = board.get_field(&target_pos) - .expect("Already validated in-bounds position"); - - let this_team = start_field - .get_team() - .ok_or_else(|| PiranhasError::new_err("Start position is not on fish field"))?; - - let mut blocked_fields = this_team.get_fish_types(); - blocked_fields.push(FieldType::Squid); - - if blocked_fields.contains(&target_field) { - return Err(PiranhasError::new_err("Cannot swim onto field of own team or squid")); - } - - let distance = Self::move_distance(board, move_); - let direction_fields = board.get_fields_in_direction(&move_.start, &move_.direction); - let path_fields: Vec<_> = direction_fields.iter().take(distance - 1).cloned().collect(); // not including start or target - - for d in path_fields { - let mut blocked_fields = this_team.get_fish_types(); - blocked_fields.push(FieldType::Squid); - - if this_team.opponent().get_fish_types().contains(&d) { - return Err(PiranhasError::new_err("Cannot swim over other team's fish")); - } - } - - Ok(()) - } - - #[staticmethod] - pub fn get_team_on_turn(turn: usize) -> TeamEnum { - if turn.is_multiple_of(2) { - TeamEnum::One - } else { - TeamEnum::Two - } - } - - #[staticmethod] - pub fn swarm_from(board: &Board, position: &Coordinate) -> Vec { - - if !RulesEngine::is_in_bounds(position) { - return vec![]; - } - - let Some(this_team) = board.get_field(position).unwrap().get_team() else { - return vec![]; - }; - - let mut todo: Vec = vec![position.to_owned()]; - let mut visited: Vec = Vec::new(); - - while !todo.is_empty() { - - let neighbors = RulesEngine::valid_neighbors(&todo[0]); - for n in neighbors { - if visited.contains(&n) || todo.contains(&n) { - continue; - } - - if let Some(team) = board.get_field(&n).unwrap().get_team() { - if team == this_team { - todo.push(n) - } - } - } - - visited.push(todo[0]); - todo.remove(0); - } - - visited - } - - #[staticmethod] - pub fn swarms_of_team(board: &Board, team: &TeamEnum) -> Vec> { - - let mut team_fish: Vec = Vec::new(); - for f in team.get_fish_types() { - team_fish.extend(board.get_fields_by_type(f)); - } - - let mut swarms: Vec> = Vec::new(); - while !team_fish.is_empty() { - let visited = RulesEngine::swarm_from(board, &team_fish[0]); - - for v in &visited { - if let Some(index) = team_fish.iter().position(|x| x == v) { - team_fish.remove(index); - } - } - - swarms.push(visited) - } - - swarms - } -} - -// rust exclusive methods -impl RulesEngine { - pub fn valid_neighbors(position: &Coordinate) -> Vec { - - let mut coordinates: Vec = Vec::new(); - - for d in Direction::all_directions() { - let neighbor = position.add_vector(&d.to_vector()); - if RulesEngine::is_in_bounds(&neighbor) { - coordinates.push(neighbor); - } - } - - coordinates - } -} \ No newline at end of file diff --git a/src/plugin2026/test/board_test.rs b/src/plugin2026/test/board_test.rs deleted file mode 100644 index 1ff3caa..0000000 --- a/src/plugin2026/test/board_test.rs +++ /dev/null @@ -1,104 +0,0 @@ -#[cfg(test)] -mod tests { - use crate::plugin2026::{ - field_type::FieldType, test::common::*, utils::{ - coordinate::Coordinate, - direction::Direction - } - }; - - #[test] - pub fn get_field_test() { - let b = create_test_board(); - - assert_eq!(b.get_field(&Coordinate { x: 0, y: 4 }), Some(FieldType::OneS)); - assert_eq!(b.get_field(&Coordinate { x: 7, y: 0 }), Some(FieldType::TwoL)); - assert_eq!(b.get_field(&Coordinate { x: 3, y: 3 }), Some(FieldType::Empty)); - assert_eq!(b.get_field(&Coordinate { x: 6, y: 2 }), Some(FieldType::Squid)); - assert_eq!(b.get_field(&Coordinate { x: -2, y: 0 }), None); // out of bounds - } - - #[test] - pub fn get_fields_by_type_test() { - let mut b = create_test_board(); - - // remove squids - b.map[2][6] = FieldType::Empty; - b.map[7][3] = FieldType::Empty; - - let one_s_positions = vec![ - Coordinate {x: 0, y: 2}, - Coordinate {x: 9, y: 2}, - Coordinate {x: 0, y: 4}, - Coordinate {x: 0, y: 6}, - Coordinate {x: 9, y: 7}, - Coordinate {x: 0, y: 8}, - Coordinate {x: 9, y: 8}, - ]; - - assert_eq!(b.get_fields_by_type(FieldType::OneS), one_s_positions); - assert_eq!(b.get_fields_by_type(FieldType::Squid), vec![]); - } - - #[test] - pub fn get_fields_in_direction_test() { - let b = create_test_board(); - let start = Coordinate {x: 2, y: 6}; - - for d in Direction::all_directions() { - match d { - Direction::Up => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ - FieldType::Empty, FieldType::Empty, FieldType::TwoS - ]), - Direction::UpRight => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ - FieldType::Squid, FieldType::Empty, FieldType::TwoM - ]), - Direction::Right => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ - FieldType::Empty, FieldType::Empty, FieldType::Empty, - FieldType::Empty, FieldType::Empty, FieldType::Empty, FieldType::OneM - ]), - Direction::DownRight => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ - FieldType::Empty, FieldType::Empty, FieldType::Empty, - FieldType::Squid, FieldType::Empty, FieldType::TwoS - ]), - Direction::Down => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ - FieldType::Empty, FieldType::Empty, FieldType::Empty, - FieldType::Empty, FieldType::Empty, FieldType::TwoS - ]), - Direction::DownLeft => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ - FieldType::Empty, FieldType::OneS - ]), - Direction::Left => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ - FieldType::Empty, FieldType::OneS - ]), - Direction::UpLeft => assert_eq!(b.get_fields_in_direction(&start, &d), vec![ - FieldType::Empty, FieldType::OneS - ]), - } - } - } - - #[test] - pub fn get_fields_on_line_test() { - let b = create_test_board(); - let start = Coordinate {x: 2, y: 7}; - let direction = Direction::Right; - - assert_eq!(b.get_fields_on_line(&start, &direction), vec![ - FieldType::OneL, FieldType::Empty, FieldType::Empty, - FieldType::Squid, FieldType::Empty, FieldType::Empty, - FieldType::Empty, FieldType::Empty, FieldType::Empty, FieldType::OneS - ]); - } - - #[test] - pub fn get_fish_on_line_test() { - let b = create_test_board(); - let start = Coordinate {x: 2, y: 7}; - let direction = Direction::Right; - - assert_eq!(b.get_fish_on_line(&start, &direction), vec![ - FieldType::OneL, FieldType::OneS - ]); - } -} diff --git a/src/plugin2026/test/common.rs b/src/plugin2026/test/common.rs deleted file mode 100644 index f4e26ef..0000000 --- a/src/plugin2026/test/common.rs +++ /dev/null @@ -1,42 +0,0 @@ -use crate::plugin2026::{ - board::Board, field_type::FieldType, game_state::GameState, utils::constants::PluginConstants -}; - -pub fn create_test_board() -> Board { - let example_map = [ - ["--", "T2", "T1", "T3", "T3", "T2", "T2", "T1", "T1", "--"], - ["O1", "--", "--", "--", "--", "--", "--", "--", "--", "O1"], - ["O3", "--", "--", "SQ", "--", "--", "--", "--", "--", "O1"], - ["O1", "--", "--", "--", "--", "--", "--", "--", "--", "O2"], - ["O2", "--", "--", "--", "--", "--", "--", "--", "--", "O2"], - ["O1", "--", "--", "--", "--", "--", "--", "--", "--", "O3"], - ["O3", "--", "--", "--", "--", "--", "--", "--", "--", "O3"], - ["O1", "--", "--", "--", "--", "--", "SQ", "--", "--", "O1"], - ["O2", "--", "--", "--", "--", "--", "--", "--", "--", "O2"], - ["--", "T2", "T1", "T3", "T1", "T2", "T1", "T3", "T1", "--"], - ]; - - let mut new_map = vec![vec![FieldType::Empty; PluginConstants::BOARD_HEIGHT]; PluginConstants::BOARD_WIDTH]; - - for y in 0..PluginConstants::BOARD_HEIGHT { - for x in 0..PluginConstants::BOARD_WIDTH { - match example_map[9 - y][x] { // read in reverse y because board is read from bottom to top - "O1" => {new_map[y][x] = FieldType::OneS}, - "O2" => {new_map[y][x] = FieldType::OneM}, - "O3" => {new_map[y][x] = FieldType::OneL}, - "T1" => {new_map[y][x] = FieldType::TwoS}, - "T2" => {new_map[y][x] = FieldType::TwoM}, - "T3" => {new_map[y][x] = FieldType::TwoL}, - "SQ" => {new_map[y][x] = FieldType::Squid}, - "--" => {}, // already FieldType::Empty - _ => {} - } - } - } - - Board {map: new_map} -} - -pub fn create_test_game_state() -> GameState { - GameState { board: create_test_board(), turn: 0, last_move: None } -} \ No newline at end of file diff --git a/src/plugin2026/test/game_state_test.rs b/src/plugin2026/test/game_state_test.rs deleted file mode 100644 index 532a053..0000000 --- a/src/plugin2026/test/game_state_test.rs +++ /dev/null @@ -1,87 +0,0 @@ -#[cfg(test)] -mod tests { - use crate::plugin2026::{ - field_type::FieldType, r#move::Move, test::common::create_test_game_state, utils::{coordinate::Coordinate, direction::Direction} - }; - - #[test] - pub fn possible_moves_for_test() { - let state = create_test_game_state(); - - // 3 possible moves - let position01 = Coordinate {x: 0, y: 3}; - let poss01 = state.possible_moves_for(&position01); - - assert_eq!(poss01, vec![ - Move {start: position01, direction: Direction::UpRight}, - Move {start: position01, direction: Direction::Right}, - Move {start: position01, direction: Direction::DownRight}, - ]); - - // no possible move because out of bounds start - let position02 = Coordinate {x: 0, y: -1}; - let poss02 = state.possible_moves_for(&position02); - - assert_eq!(poss02, vec![]); - } - - #[test] - pub fn possible_moves_test() { - // this state's board has 48 (standard number) moves for team one (turn 0) - // team two would have 6 turns less from this position due to squids - let mut state = create_test_game_state(); - - assert_eq!(state.possible_moves().len(), 48); // team one - - state.turn = 1; - assert_eq!(state.possible_moves().len(), 42); // team two - } - - #[test] - pub fn perform_move_test() { - pyo3::prepare_freethreaded_python(); - - let mut state = create_test_game_state(); - - // correct move - let new_state = state.perform_move( &Move { - start: Coordinate { x: 0, y: 3 }, - direction: Direction::Right - }).unwrap(); - - assert_eq!(new_state.board.get_field(&Coordinate { x: 0, y: 3 }), Some(FieldType::Empty)); - assert_eq!(new_state.board.get_field(&Coordinate { x: 2, y: 3 }), Some(FieldType::OneL)); - - // illegal moves - let result = state.perform_move(&Move { - start: Coordinate { x: -1, y: 0 }, - direction: Direction::Right - }); - assert!(result.is_err(), "Move FROM out of bounds should fail, but succeeded"); - - let result = state.perform_move(&Move { - start: Coordinate { x: 0, y: 3 }, - direction: Direction::Left - }); - assert!(result.is_err(), "Move TO out of bounds should fail, but succeeded"); - - let result = state.perform_move(&Move { - start: Coordinate { x: 3, y: 3 }, - direction: Direction::Right - }); - assert!(result.is_err(), "Move FROM non-fish field should fail, but succeeded"); - - let result = state.perform_move(&Move { - start: Coordinate { x: 6, y: 0 }, - direction: Direction::Up - }); - assert!(result.is_err(), "Move TO squid field should fail, but succeeded"); - - state.board.map[3][2] = FieldType::TwoL; - let result = state.perform_move(&Move { - start: Coordinate { x: 2, y: 0 }, - direction: Direction::Up - }); - assert!(result.is_err(), "Move TO own-fish field should fail, but succeeded"); - } -} diff --git a/src/plugin2026/test/mod.rs b/src/plugin2026/test/mod.rs deleted file mode 100644 index 5d21ff2..0000000 --- a/src/plugin2026/test/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[cfg(test)] -mod common; -#[cfg(test)] -mod board_test; -#[cfg(test)] -mod game_state_test; \ No newline at end of file diff --git a/src/plugin2026/utils.rs b/src/plugin2026/utils.rs deleted file mode 100644 index b41dac7..0000000 --- a/src/plugin2026/utils.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod vector; -pub mod direction; -pub mod constants; -pub mod coordinate; -pub mod team; \ No newline at end of file diff --git a/src/plugin2026/utils/constants.rs b/src/plugin2026/utils/constants.rs deleted file mode 100644 index 88a09bf..0000000 --- a/src/plugin2026/utils/constants.rs +++ /dev/null @@ -1,12 +0,0 @@ -use pyo3::*; - -#[pyclass] -pub struct PluginConstants; - -#[pymethods] -impl PluginConstants { - pub const BOARD_WIDTH: usize = 10; - pub const BOARD_HEIGHT: usize = 10; - - pub const ROUND_LIMIT: usize = 30; -} diff --git a/src/plugin2026/utils/coordinate.rs b/src/plugin2026/utils/coordinate.rs deleted file mode 100644 index 02af65d..0000000 --- a/src/plugin2026/utils/coordinate.rs +++ /dev/null @@ -1,54 +0,0 @@ -use pyo3::*; - -use crate::plugin2026::{utils::vector::Vector}; - -#[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct Coordinate { - #[pyo3(get, set)] - pub x: isize, - #[pyo3(get, set)] - pub y: isize, -} - -#[pymethods] -impl Coordinate { - #[new] - pub fn new(x: isize, y: isize) -> Self { - Self { - x, y - } - } - - fn __str__(&self) -> String {self.to_string()} - fn __repr__(&self) -> String {format!("{:?}", self)} - fn __eq__(&self, other: &Coordinate) -> bool {self == other} - fn __ne__(&self, other: &Coordinate) -> bool {self != other} - fn deepcopy(&self) -> Coordinate {*self} - - pub fn add_vector(&self, vector: &Vector) -> Coordinate { - Coordinate { - x: self.x + vector.delta_x, - y: self.y + vector.delta_y - } - } - - pub fn add_vector_mut(&mut self, vector: &Vector) { - - self.x += vector.delta_x; - self.y += vector.delta_y; - } - - pub fn get_difference(&self, other: &Coordinate) -> Vector { - Vector { - delta_x: other.x - self.x, - delta_y: other.y - self.y - } - } -} - -impl std::fmt::Display for Coordinate { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "({}, {})", self.x, self.y) - } -} \ No newline at end of file diff --git a/src/plugin2026/utils/direction.rs b/src/plugin2026/utils/direction.rs deleted file mode 100644 index d127039..0000000 --- a/src/plugin2026/utils/direction.rs +++ /dev/null @@ -1,97 +0,0 @@ -use pyo3::*; - -use crate::plugin2026::{ - utils::vector::Vector -}; - -#[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum Direction { - Up, - UpRight, - Right, - DownRight, - Down, - DownLeft, - Left, - UpLeft -} - -#[pymethods] -impl Direction { - fn __str__(&self) -> String {self.to_string()} - fn __repr__(&self) -> String {format!("{:?}", self)} - fn __eq__(&self, other: &Direction) -> bool {self == other} - fn __ne__(&self, other: &Direction) -> bool {self != other} - fn deepcopy(&self) -> Direction {*self} - - #[staticmethod] - pub fn from_vector(vector: &Vector) -> Option { - match (vector.delta_x, vector.delta_y) { - (0, 1) => Some(Direction::Up), - (1, 1) => Some(Direction::UpRight), - (1, 0) => Some(Direction::Right), - (1, -1) => Some(Direction::DownRight), - (0, -1) => Some(Direction::Down), - (-1, -1) => Some(Direction::DownLeft), - (-1, 0) => Some(Direction::Left), - (-1, 1) => Some(Direction::UpLeft), - _ => None, - } - } - - #[staticmethod] - pub fn all_directions() -> Vec { - vec![ - Direction::Up, - Direction::UpRight, - Direction::Right, - Direction::DownRight, - Direction::Down, - Direction::DownLeft, - Direction::Left, - Direction::UpLeft - ] - } - - pub fn to_vector(&self) -> Vector { - match self { - Direction::Up => Vector { delta_x: 0, delta_y: 1 }, - Direction::UpRight => Vector { delta_x: 1, delta_y: 1 }, - Direction::Right => Vector { delta_x: 1, delta_y: 0 }, - Direction::DownRight => Vector { delta_x: 1, delta_y: -1 }, - Direction::Down => Vector { delta_x: 0, delta_y: -1 }, - Direction::DownLeft => Vector { delta_x: -1, delta_y: -1 }, - Direction::Left => Vector { delta_x: -1, delta_y: 0 }, - Direction::UpLeft => Vector { delta_x: -1, delta_y: 1 }, - } - } - - pub fn to_mirrored(&self) -> Direction { - match self { - Direction::Up => Direction::Down, - Direction::UpRight => Direction::DownLeft, - Direction::Right => Direction::Left, - Direction::DownRight => Direction::UpLeft, - Direction::Down => Direction::Up, - Direction::DownLeft => Direction::UpRight, - Direction::Left => Direction::Right, - Direction::UpLeft => Direction::DownRight, - } - } -} - -impl std::fmt::Display for Direction { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Direction::Up => write!(f, "(Up ↑)"), - Direction::UpRight => write!(f, "(UpRight ↗)"), - Direction::Right => write!(f, "(Right →)"), - Direction::DownRight => write!(f, "(DownRight ↘)"), - Direction::Down => write!(f, "(Down ↓)"), - Direction::DownLeft => write!(f, "(DownLeft ↙)"), - Direction::Left => write!(f, "(Left ←)"), - Direction::UpLeft => write!(f, "(UpLeft ↖)") - } - } -} diff --git a/src/plugin2026/utils/team.rs b/src/plugin2026/utils/team.rs deleted file mode 100644 index 078c842..0000000 --- a/src/plugin2026/utils/team.rs +++ /dev/null @@ -1,41 +0,0 @@ -use pyo3::*; - -use crate::plugin2026::field_type::FieldType; - -#[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum TeamEnum { - One, - Two, -} - -#[pymethods] -impl TeamEnum { - fn __str__(&self) -> String {self.to_string()} - fn __repr__(&self) -> String {format!("{:?}", self)} - fn __eq__(&self, other: &TeamEnum) -> bool {self == other} - fn __ne__(&self, other: &TeamEnum) -> bool {self != other} - - pub fn get_fish_types(&self) -> Vec { - match self { - TeamEnum::One => vec![FieldType::OneS, FieldType::OneM, FieldType::OneL], - TeamEnum::Two => vec![FieldType::TwoS, FieldType::TwoM, FieldType::TwoL] - } - } - - pub fn opponent(&self) -> TeamEnum { - match self { - TeamEnum::One => TeamEnum::Two, - TeamEnum::Two => TeamEnum::One - } - } -} - -impl std::fmt::Display for TeamEnum { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Self::One => write!(f, "Team One"), - Self::Two => write!(f, "Team Two") - } - } -} \ No newline at end of file diff --git a/src/plugin2026/utils/vector.rs b/src/plugin2026/utils/vector.rs deleted file mode 100644 index 8b0b4af..0000000 --- a/src/plugin2026/utils/vector.rs +++ /dev/null @@ -1,66 +0,0 @@ -use pyo3::*; - -#[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct Vector { - #[pyo3(get, set)] - pub delta_x: isize, - #[pyo3(get, set)] - pub delta_y: isize, -} - -#[pymethods] -impl Vector { - #[new] - pub fn new(delta_x: isize, delta_y: isize) -> Self { - Self { - delta_x, delta_y - } - } - - fn __str__(&self) -> String {self.to_string()} - fn __repr__(&self) -> String {format!("{:?}", self)} - fn __eq__(&self, other: &Vector) -> bool {self == other} - fn __ne__(&self, other: &Vector) -> bool {self != other} - fn deepcopy(&self) -> Vector {*self} - - pub fn add_vector(&self, other: &Vector) -> Vector { - Vector { - delta_x: self.delta_x + other.delta_x, - delta_y: self.delta_y + other.delta_y - } - } - - pub fn add_vector_mut(&mut self, other: &Vector) { - self.delta_x += other.delta_x; - self.delta_y += other.delta_y; - } - - pub fn scale(&self, scalar: isize) -> Vector { - Vector { - delta_x: self.delta_x * scalar, - delta_y: self.delta_y * scalar - } - } - - pub fn scale_mut(&mut self, scalar: isize) { - self.delta_x *= scalar; - self.delta_y *= scalar; - } - - pub fn get_length(&self) -> Option { - let squared_length = self.delta_x * self.delta_x + self.delta_y * self.delta_y; - - if squared_length < 0 { - None // Return None for negative numbers - } else { - Some((squared_length as f32).sqrt()) // Convert to f32 then compute sqrt - } - } -} - -impl std::fmt::Display for Vector { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "vec({}, {})", self.delta_x, self.delta_y) - } -} \ No newline at end of file