Compare commits
4 Commits
205111d25f
...
e7f4a00f2a
| Author | SHA1 | Date | |
|---|---|---|---|
| e7f4a00f2a | |||
| bd324807e8 | |||
| 4a17666bba | |||
|
|
daf05e3609 |
78
src/card.rs
78
src/card.rs
@@ -1,10 +1,8 @@
|
|||||||
//! TODO: module doc :v
|
//! TODO: module doc :v
|
||||||
|
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
/// Value for the "sub tiles" inside a room tile
|
/// Value for the "sub tiles" inside a room tile
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||||
enum Cell {
|
pub enum Cell {
|
||||||
#[default]
|
#[default]
|
||||||
Empty,
|
Empty,
|
||||||
NW,
|
NW,
|
||||||
@@ -15,7 +13,7 @@ enum Cell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
enum CutLine {
|
pub enum CutLine {
|
||||||
VertLeft,
|
VertLeft,
|
||||||
VertRight,
|
VertRight,
|
||||||
HorizUpper,
|
HorizUpper,
|
||||||
@@ -23,26 +21,26 @@ enum CutLine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
enum FlipDir {
|
pub enum FlipDir {
|
||||||
Vertical,
|
Vertical,
|
||||||
Horizontal,
|
Horizontal,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
enum TransposeIndex {
|
pub enum TransposeIndex {
|
||||||
First,
|
First,
|
||||||
Second,
|
Second,
|
||||||
Third,
|
Third,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
enum TransposeSelection {
|
pub enum TransposeSelection {
|
||||||
Column(TransposeIndex),
|
Column(TransposeIndex),
|
||||||
Row(TransposeIndex),
|
Row(TransposeIndex),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
enum RotationDir {
|
pub enum RotationDir {
|
||||||
Clockwise,
|
Clockwise,
|
||||||
CounterClockwise,
|
CounterClockwise,
|
||||||
}
|
}
|
||||||
@@ -50,7 +48,7 @@ enum RotationDir {
|
|||||||
/// An invidiual room, or "card" in the player's hand. The room may
|
/// An invidiual room, or "card" in the player's hand. The room may
|
||||||
/// *or may not* be valid, yet.
|
/// *or may not* be valid, yet.
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||||
struct Card {
|
pub struct Card {
|
||||||
cells: [Cell; 9],
|
cells: [Cell; 9],
|
||||||
nw: bool,
|
nw: bool,
|
||||||
n: bool,
|
n: bool,
|
||||||
@@ -115,19 +113,19 @@ impl Card {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Cuts this Card on the given line. Returns two cards
|
/// Cuts this Card on the given line. Returns two cards
|
||||||
pub fn cut(&self, line: CutLine) -> (Self, Self) {
|
pub fn cut(self, line: CutLine) -> (Self, Self) {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flip(&self, flip: FlipDir) -> (Self) {
|
pub fn flip(self, flip: FlipDir) -> Self {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transpose(&self, other: &Self, selection: TransposeSelection) -> (Self, Self) {
|
pub fn transpose(self, other: Self, selection: TransposeSelection) -> (Self, Self) {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rotate(&self, dir: RotationDir) {
|
pub fn rotate(self, dir: RotationDir) {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -191,6 +189,60 @@ mod test {
|
|||||||
assert!(extra_doors.is_none());
|
assert!(extra_doors.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_merge_doors() {
|
||||||
|
let bottom = Card {
|
||||||
|
cells: NW_TRIANGLE,
|
||||||
|
s: true, // Test that this is not overwritten by an empty tile
|
||||||
|
se: true, // Test that this is subsumed by another door
|
||||||
|
e: true, // Test that this is popped off into the second card
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let top = Card {
|
||||||
|
cells: [
|
||||||
|
Cell::Empty,
|
||||||
|
Cell::Empty,
|
||||||
|
Cell::Empty,
|
||||||
|
Cell::Empty,
|
||||||
|
Cell::Empty,
|
||||||
|
Cell::Filled,
|
||||||
|
Cell::Empty,
|
||||||
|
Cell::Empty,
|
||||||
|
Cell::Filled,
|
||||||
|
],
|
||||||
|
se: true, // Test that this is subsumed by another door
|
||||||
|
n: true, // Test that is is dropped because no floor
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let expected = Card {
|
||||||
|
cells: [
|
||||||
|
Cell::Empty,
|
||||||
|
Cell::Empty,
|
||||||
|
Cell::NW,
|
||||||
|
Cell::Empty,
|
||||||
|
Cell::NW,
|
||||||
|
Cell::Filled,
|
||||||
|
Cell::NW,
|
||||||
|
Cell::Filled,
|
||||||
|
Cell::Filled,
|
||||||
|
],
|
||||||
|
s: true,
|
||||||
|
se: true,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let expected_doors = Card {
|
||||||
|
e: true,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let (stacked, extra_doors) = bottom.merge(top);
|
||||||
|
assert_eq!(stacked, expected);
|
||||||
|
assert_eq!(extra_doors, Some(expected_doors));
|
||||||
|
}
|
||||||
|
|
||||||
/// Merging two triangular [`Cell`]s should prefer the top-most one, *unless*
|
/// Merging two triangular [`Cell`]s should prefer the top-most one, *unless*
|
||||||
/// they are opposites. See test [`merge_opposite_triangles()`].
|
/// they are opposites. See test [`merge_opposite_triangles()`].
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user