diff --git a/Cargo.toml b/Cargo.toml index 0821a1b..b60ffeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "_socha" -version = "4.1.1" +version = "4.2.0" edition = "2021" [lib] diff --git a/pyproject.toml b/pyproject.toml index 49842a4..7789bc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "socha" -version = "4.1.1" +version = "4.2.0" authors = [ { name = "yoente", email = "stu250140@mail.uni-kiel.de" }, { name = "maxblan", email = "stu222782@mail.uni-kiel.de" }, diff --git a/python/socha/_socha.pyi b/python/socha/_socha.pyi index 7e623de..eacf72a 100644 --- a/python/socha/_socha.pyi +++ b/python/socha/_socha.pyi @@ -16,6 +16,36 @@ class Coordinate: def __init__(self, x: int, y: int) -> None: ... def __str__(self) -> str: ... def __repr__(self) -> str: ... + def __eq__(self, other: Coordinate) -> bool: + """ + Unterstützt den Vergleichsoperator ==, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (Coordinate): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + def __ne__(self, other: Coordinate) -> bool: + """ + Unterstützt den Vergleichsoperator !=, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (Coordinate): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + + def deepcopy(self) -> Coordinate: + """ + Kopiert das Objekt rekursiv. + """ + ... def add_vector(self, vector: Vector) -> Coordinate: """ @@ -65,6 +95,36 @@ class Vector: def __init__(self, delta_x: int, delta_y: int) -> None: ... def __str__(self) -> str: ... def __repr__(self) -> str: ... + def __eq__(self, other: Vector) -> bool: + """ + Unterstützt den Vergleichsoperator ==, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (Vector): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + def __ne__(self, other: Vector) -> bool: + """ + Unterstützt den Vergleichsoperator !=, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (Vector): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + + def deepcopy(self) -> GameState: + """ + Kopiert das Objekt rekursiv. + """ + ... def add_vector(self, other: Vector) -> Vector: """ @@ -158,6 +218,30 @@ class Direction(Enum): def __str__(self) -> str: ... def __repr__(self) -> str: ... + def __eq__(self, other: Direction) -> bool: + """ + Unterstützt den Vergleichsoperator ==, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (Direction): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + def __ne__(self, other: Direction) -> bool: + """ + Unterstützt den Vergleichsoperator !=, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (Direction): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... @staticmethod def from_vector(vector: Vector) -> Optional[Direction]: @@ -242,6 +326,30 @@ class FieldType(Enum): def __str__(self) -> str: ... def __repr__(self) -> str: ... + def __eq__(self, other: FieldType) -> bool: + """ + Unterstützt den Vergleichsoperator ==, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (FieldType): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + def __ne__(self, other: FieldType) -> bool: + """ + Unterstützt den Vergleichsoperator !=, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (FieldType): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... def get_value(self) -> int: """ @@ -288,6 +396,30 @@ class TeamEnum(Enum): def __str__(self) -> str: ... def __repr__(self) -> str: ... + def __eq__(self, other: TeamEnum) -> bool: + """ + Unterstützt den Vergleichsoperator ==, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (TeamEnum): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + def __ne__(self, other: TeamEnum) -> bool: + """ + Unterstützt den Vergleichsoperator !=, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (TeamEnum): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... def get_fish_types(self) -> List[FieldType]: """ @@ -323,6 +455,37 @@ class Board: def __init__(self, map: List[List[FieldType]]) -> None: ... def __str__(self) -> str: ... def __repr__(self) -> str: ... + + def __eq__(self, other: TeamEnum) -> bool: + """ + Unterstützt den Vergleichsoperator ==, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (TeamEnum): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + def __ne__(self, other: TeamEnum) -> bool: + """ + Unterstützt den Vergleichsoperator !=, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (TeamEnum): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + + def deepcopy(self) -> GameState: + """ + Kopiert das Objekt rekursiv. + """ + ... def get_field(self, position: Coordinate) -> Optional[FieldType]: """ @@ -410,6 +573,37 @@ class Move: def __init__(self, start: Coordinate, direction: Direction) -> None: ... def __str__(self) -> str: ... def __repr__(self) -> str: ... + + def __eq__(self, other: Move) -> bool: + """ + Unterstützt den Vergleichsoperator ==, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (Move): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + def __ne__(self, other: Move) -> bool: + """ + Unterstützt den Vergleichsoperator !=, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (Move): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + + def deepcopy(self) -> GameState: + """ + Kopiert das Objekt rekursiv. + """ + ... class GameState: """ @@ -428,6 +622,46 @@ class GameState: def __init__(self, board: Board, turn: int, last_move: Optional[Move]) -> None: ... def __str__(self) -> str: ... def __repr__(self) -> str: ... + def __eq__(self, other: GameState) -> bool: + """ + Unterstützt den Vergleichsoperator ==, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (GameState): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + def __ne__(self, other: GameState) -> bool: + """ + Unterstützt den Vergleichsoperator !=, um die Werte mit denen eines + weiteren Objektes zuvergleichen. + + Args: + other: (GameState): Die andere Koordinate. + + Returns: + bool: Das Ergebnis des Vergleichs. + """ + ... + + def deepcopy(self) -> GameState: + """ + Kopiert das Objekt rekursiv. + """ + ... + + def set_board_field(self, position: Coordinate, field: FieldType) -> None: + """ + Ändert ein Feld auf dem Spielfeld an einer Koordinate. + + Args: + position (Coordinate): Die Position des Feldes, das geändert werden soll. + field (FieldType): Das Feld, was dort platziert werden soll. + """ + ... def possible_moves_for(self, start: Coordinate) -> List[Move]: """ @@ -498,7 +732,6 @@ class RulesEngine: """ ... - @staticmethod def target_position(board: Board, move_: Move) -> Coordinate: """ diff --git a/src/plugin2026/board.rs b/src/plugin2026/board.rs index b5b924a..3a589fb 100644 --- a/src/plugin2026/board.rs +++ b/src/plugin2026/board.rs @@ -10,7 +10,7 @@ use crate::plugin2026::{ }; #[pyclass] -#[derive(PartialEq, Eq, PartialOrd, Clone, Debug, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Board { #[pyo3(get, set)] pub map: Vec>, @@ -25,6 +25,10 @@ impl Board { pub fn __str__(&self) -> String {self.to_string()} pub fn __repr__(&self) -> String {format!("{:?}", self)} + pub fn __eq__(&self, other: &Board) -> bool {self == other} + pub fn __ne_(&self, other: &Board) -> bool {self != other} + + pub fn deepcopy(&self) -> Board {self.clone()} pub fn get_field(&self, position: &Coordinate) -> Option { diff --git a/src/plugin2026/field_type.rs b/src/plugin2026/field_type.rs index da496e7..022aa81 100644 --- a/src/plugin2026/field_type.rs +++ b/src/plugin2026/field_type.rs @@ -3,7 +3,7 @@ use pyo3::*; use crate::plugin2026::utils::team::TeamEnum; #[pyclass] -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum FieldType { OneS, OneM, @@ -19,6 +19,8 @@ pub enum FieldType { impl FieldType { pub fn __str__(&self) -> String {self.to_string()} pub fn __repr__(&self) -> String {format!("{:?}", self)} + pub fn __eq__(&self, other: &FieldType) -> bool {self == other} + pub fn __ne_(&self, other: &FieldType) -> bool {self != other} pub fn get_value(&self) -> usize { match self { diff --git a/src/plugin2026/game_state.rs b/src/plugin2026/game_state.rs index b6f7c60..6b5be58 100644 --- a/src/plugin2026/game_state.rs +++ b/src/plugin2026/game_state.rs @@ -8,7 +8,7 @@ use crate::plugin2026::{ }; #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct GameState { #[pyo3(get, set)] pub board: Board, @@ -31,6 +31,23 @@ impl GameState { pub fn __str__(&self) -> String {self.to_string()} pub fn __repr__(&self) -> String {format!("{:?}", self)} + pub fn __eq__(&self, other: &GameState) -> bool {self == other} + pub fn __ne__(&self, other: &GameState) -> bool {self != other} + + pub 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(); diff --git a/src/plugin2026/move.rs b/src/plugin2026/move.rs index c8681c7..4079a28 100644 --- a/src/plugin2026/move.rs +++ b/src/plugin2026/move.rs @@ -10,7 +10,7 @@ use crate::plugin2026::{ }; #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Move { #[pyo3(get, set)] pub start: Coordinate, @@ -29,6 +29,10 @@ impl Move { pub fn __str__(&self) -> String {self.to_string()} pub fn __repr__(&self) -> String {format!("{:?}", self)} + pub fn __eq__(&self, other: &Move) -> bool {self == other} + pub fn __ne_(&self, other: &Move) -> bool {self != other} + + pub fn deepcopy(&self) -> Move {self.clone()} } impl std::fmt::Display for Move { diff --git a/src/plugin2026/test/game_state_test.rs b/src/plugin2026/test/game_state_test.rs index 83ab624..532a053 100644 --- a/src/plugin2026/test/game_state_test.rs +++ b/src/plugin2026/test/game_state_test.rs @@ -13,9 +13,9 @@ mod tests { let poss01 = state.possible_moves_for(&position01); assert_eq!(poss01, vec![ - Move {start: position01.clone(), direction: Direction::UpRight}, - Move {start: position01.clone(), direction: Direction::Right}, - Move {start: position01.clone(), direction: Direction::DownRight}, + 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 diff --git a/src/plugin2026/utils/coordinate.rs b/src/plugin2026/utils/coordinate.rs index 4d0d39c..0f86dab 100644 --- a/src/plugin2026/utils/coordinate.rs +++ b/src/plugin2026/utils/coordinate.rs @@ -3,7 +3,7 @@ use pyo3::*; use crate::plugin2026::{utils::vector::Vector}; #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Coordinate { #[pyo3(get, set)] pub x: isize, @@ -22,6 +22,10 @@ impl Coordinate { pub fn __str__(&self) -> String {self.to_string()} pub fn __repr__(&self) -> String {format!("{:?}", self)} + pub fn __eq__(&self, other: &Coordinate) -> bool {self == other} + pub fn __ne_(&self, other: &Coordinate) -> bool {self != other} + + pub fn deepcopy(&self) -> Coordinate {*self} pub fn add_vector(&self, vector: &Vector) -> Coordinate { Coordinate { diff --git a/src/plugin2026/utils/direction.rs b/src/plugin2026/utils/direction.rs index d60ba2a..f6faca5 100644 --- a/src/plugin2026/utils/direction.rs +++ b/src/plugin2026/utils/direction.rs @@ -5,7 +5,7 @@ use crate::plugin2026::{ }; #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Direction { Up, UpRight, @@ -21,6 +21,10 @@ pub enum Direction { impl Direction { pub fn __str__(&self) -> String {self.to_string()} pub fn __repr__(&self) -> String {format!("{:?}", self)} + pub fn __eq__(&self, other: &Direction) -> bool {self == other} + pub fn __ne_(&self, other: &Direction) -> bool {self != other} + + pub fn deepcopy(&self) -> Direction {*self} #[staticmethod] pub fn from_vector(vector: &Vector) -> Option { diff --git a/src/plugin2026/utils/team.rs b/src/plugin2026/utils/team.rs index 6ad5c18..ad3dc08 100644 --- a/src/plugin2026/utils/team.rs +++ b/src/plugin2026/utils/team.rs @@ -3,7 +3,7 @@ use pyo3::*; use crate::plugin2026::field_type::FieldType; #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum TeamEnum { One, Two, @@ -13,6 +13,8 @@ pub enum TeamEnum { impl TeamEnum { pub fn __str__(&self) -> String {self.to_string()} pub fn __repr__(&self) -> String {format!("{:?}", self)} + pub fn __eq__(&self, other: &TeamEnum) -> bool {self == other} + pub fn __ne_(&self, other: &TeamEnum) -> bool {self != other} pub fn get_fish_types(&self) -> Vec { match self { diff --git a/src/plugin2026/utils/vector.rs b/src/plugin2026/utils/vector.rs index 9fad462..3e16245 100644 --- a/src/plugin2026/utils/vector.rs +++ b/src/plugin2026/utils/vector.rs @@ -1,7 +1,7 @@ use pyo3::*; #[pyclass] -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Vector { #[pyo3(get, set)] pub delta_x: isize, @@ -20,6 +20,10 @@ impl Vector { pub fn __str__(&self) -> String {self.to_string()} pub fn __repr__(&self) -> String {format!("{:?}", self)} + pub fn __eq__(&self, other: &Vector) -> bool {self == other} + pub fn __ne_(&self, other: &Vector) -> bool {self != other} + + pub fn deepcopy(&self) -> Vector {*self} pub fn add_vector(&self, other: &Vector) -> Vector { Vector {