Tests pass so we are... almost cooking

main
Elijah Voigt 6 days ago
parent 0d1a680625
commit 4c35daac3e

@ -1,8 +1,6 @@
// Bevy basically forces "complex types" with Querys // Bevy basically forces "complex types" with Querys
#![allow(clippy::type_complexity)] #![allow(clippy::type_complexity)]
use bevy::render::render_resource::encase::matrix::AsMutMatrixParts;
use games::*; use games::*;
// *TODO: Detect when piece is going to go out of bounds and restirct parent from moving there // *TODO: Detect when piece is going to go out of bounds and restirct parent from moving there
@ -187,7 +185,7 @@ impl GridPosition {
} }
} }
#[derive(Error, Debug)] #[derive(Error, Debug, PartialEq)]
enum GameError { enum GameError {
#[error("Coordinates are out of bounds: Left")] #[error("Coordinates are out of bounds: Left")]
OutOfBoundsLeft, OutOfBoundsLeft,
@ -455,12 +453,35 @@ impl Shape {
} }
// TODO: return impl Iterator<Item = &RelativePosition> // TODO: return impl Iterator<Item = &RelativePosition>
fn relative_coordinates(&self) -> Vec<RelativePosition> { fn relative_coordinates(&self) -> impl Iterator<Item = RelativePosition> {
todo!() let mut v: Vec<RelativePosition> = Vec::new();
match self {
Self::M4(inner) => {
for (i, y) in (-1..3).rev().enumerate() {
let c = inner.col(i);
for (j, x) in (-1..3).enumerate() {
if c[j] == 1.0 {
v.push(RelativePosition { x, y });
}
}
}
}
Self::M3(inner) => {
for (i, y) in (-1..2).rev().enumerate() {
let c = inner.col(i);
for (j, x) in (-1..2).enumerate() {
if c[j] == 1.0 {
v.push(RelativePosition { x, y });
}
}
}
}
};
v.into_iter()
} }
fn computed_coordinates(&self, center: &GridPosition) -> Vec<GridPosition> { fn computed_coordinates(&self, center: &GridPosition) -> impl Iterator<Item = Result<GridPosition, GameError>> {
todo!() self.relative_coordinates().map(|rp| center.add_relative(&rp))
} }
fn as_ascii(&self) -> String { fn as_ascii(&self) -> String {
@ -559,14 +580,16 @@ mod test {
fn test_relative_coordinates() { fn test_relative_coordinates() {
let shape = Shape::new_t(); let shape = Shape::new_t();
let expected = vec![ let expected: Vec<RelativePosition> = vec![
(0, 1).into(),
(-1, 0).into(), (-1, 0).into(),
(0, 0).into(), (0, 0).into(),
(1, 0).into(), (1, 0).into(),
(0, 1).into(),
]; ];
assert_eq!(shape.relative_coordinates(), expected); let actual: Vec<RelativePosition> = shape.relative_coordinates().collect();
assert_eq!(actual, expected);
} }
#[test] #[test]
@ -575,14 +598,16 @@ mod test {
let center = GridPosition { x: 5, y: 5 }; let center = GridPosition { x: 5, y: 5 };
let expected = vec![ let expected: Vec<Result<GridPosition, GameError>> = vec![
(4, 5).into(), Ok((5, 6).into()),
(5, 5).into(), Ok((4, 5).into()),
(6, 5).into(), Ok((5, 5).into()),
(5, 6).into(), Ok((6, 5).into()),
]; ];
assert_eq!(shape.computed_coordinates(&center), expected); let actual: Vec<Result<GridPosition, GameError>> = shape.computed_coordinates(&center).collect();
assert_eq!(actual, expected);
} }
} }

Loading…
Cancel
Save