diff --git a/Cargo.toml b/Cargo.toml index dca1dda..6e666ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "_socha" -version = "5.1.0" +version = "5.1.1" edition = "2021" [lib] diff --git a/pyproject.toml b/pyproject.toml index ba5a780..339fe4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "socha" -version = "5.1.0" +version = "5.1.1" 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 b819d50..191262a 100644 --- a/python/socha/_socha.pyi +++ b/python/socha/_socha.pyi @@ -2,19 +2,21 @@ from enum import Enum class Vector: """ - Ein 2 dimensionaler Vektor. + Ein 2 dimensionaler Vektor. (unveränderbar) Attributes: delta_x (int): Die Entfernung in x-Richtung. delta_y (int): Die Entfernung in y-Richtung. """ - - delta_x: int - delta_y: int + @property + def delta_x(self) -> int: ... + @property + def delta_y(self) -> int: ... def __init__(self, delta_x: int, delta_y: int) -> None: ... def __eq__(self, other: object) -> bool: ... def __ne__(self, other: object) -> bool: ... + def __hash__(self) -> int: ... def deepcopy(self) -> Vector: """Kopiert das Objekt.""" @@ -22,34 +24,31 @@ class Vector: def add_vector(self, other: Vector) -> Vector: """Addiert einen anderen Vector (nicht mutierend).""" - def add_vector_mut(self, other: Vector) -> None: - """Addiert einen anderen Vector (mutierend).""" - def scale(self, scalar: int) -> Vector: """Skaliert diesen Vektor (nicht mutierend).""" - def scale_mut(self, scalar: int) -> None: - """Skaliert diesen Vektor (mutierend).""" - def get_length(self) -> float | None: """Berechnet die Länge dieses Vektors.""" class Coordinate: """ - Eine 2 dimensionale Koordinate auf einem Spielfeld. + Eine 2 dimensionale Koordinate auf einem Spielfeld. (unveränderbar) Attributes: x (int): Der x-Wert. y (int): Der y-Wert. """ - x: int - y: int + @property + def x(self) -> int: ... + @property + def y(self) -> int: ... def __init__(self, x: int, y: int) -> None: ... def __eq__(self, other: object) -> bool: ... def __ne__(self, other: object) -> bool: ... + def __hash__(self) -> int: ... def deepcopy(self) -> Coordinate: """Kopiert das Objekt.""" @@ -57,9 +56,6 @@ class Coordinate: def add_vector(self, vector: Vector) -> Coordinate: """Addiert einen Vector auf diese Koordinate (nicht mutierend).""" - def add_vector_mut(self, vector: Vector) -> None: - """Addiert einen Vector auf diese Koordinate (mutierend).""" - def get_difference(self, other: Coordinate) -> Vector: """Berechnet die Differenz zwischen zwei Koordinaten als Vektor.""" diff --git a/src/plugin2027/piece.rs b/src/plugin2027/piece.rs index 89ba74d..ac2c585 100644 --- a/src/plugin2027/piece.rs +++ b/src/plugin2027/piece.rs @@ -9,15 +9,15 @@ use crate::plugin2027::{ #[pyclass(from_py_object)] #[derive(Debug, Clone)] pub struct Piece { - #[pyo3(get, set)] + #[pyo3(get)] pub color: Color, - #[pyo3(get, set)] + #[pyo3(get)] pub kind: PieceShape, - #[pyo3(get, set)] + #[pyo3(get)] pub rotation: Rotation, - #[pyo3(get, set)] + #[pyo3(get)] pub is_flipped: bool, - #[pyo3(get, set)] + #[pyo3(get)] pub position: Coordinate, } diff --git a/src/plugin2027/utils/coordinate.rs b/src/plugin2027/utils/coordinate.rs index fcacc2e..77e70fc 100644 --- a/src/plugin2027/utils/coordinate.rs +++ b/src/plugin2027/utils/coordinate.rs @@ -1,4 +1,5 @@ use pyo3::*; +use std::hash::{DefaultHasher, Hash, Hasher}; use crate::plugin2027::{ utils::vector::Vector, utils::direction::Direction @@ -7,9 +8,9 @@ use crate::plugin2027::{ #[pyclass(from_py_object)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Coordinate { - #[pyo3(get, set)] + #[pyo3(get)] pub x: isize, - #[pyo3(get, set)] + #[pyo3(get)] pub y: isize, } @@ -26,6 +27,11 @@ impl Coordinate { fn __repr__(&self) -> String {format!("{:?}", self)} fn __eq__(&self, other: &Coordinate) -> bool {self == other} fn __ne__(&self, other: &Coordinate) -> bool {self != other} + fn __hash__(&self) -> u64 { + let mut hasher = DefaultHasher::new(); + self.hash(&mut hasher); + hasher.finish() + } fn deepcopy(&self) -> Coordinate {*self} pub fn add_vector(&self, vector: &Vector) -> Coordinate { @@ -35,12 +41,6 @@ impl Coordinate { } } - 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, diff --git a/src/plugin2027/utils/vector.rs b/src/plugin2027/utils/vector.rs index b2ce1ae..a97356c 100644 --- a/src/plugin2027/utils/vector.rs +++ b/src/plugin2027/utils/vector.rs @@ -1,11 +1,12 @@ use pyo3::*; +use std::hash::{DefaultHasher, Hash, Hasher}; #[pyclass(from_py_object)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Vector { - #[pyo3(get, set)] + #[pyo3(get)] pub delta_x: isize, - #[pyo3(get, set)] + #[pyo3(get)] pub delta_y: isize, } @@ -22,6 +23,12 @@ impl Vector { fn __repr__(&self) -> String {format!("{:?}", self)} fn __eq__(&self, other: &Vector) -> bool {self == other} fn __ne__(&self, other: &Vector) -> bool {self != other} + fn __hash__(&self) -> u64 { + let mut hasher = DefaultHasher::new(); + self.hash(&mut hasher); + hasher.finish() + } + fn deepcopy(&self) -> Vector {*self} pub fn add_vector(&self, other: &Vector) -> Vector { @@ -30,11 +37,6 @@ impl Vector { 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 { @@ -43,11 +45,6 @@ impl Vector { } } - 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;