-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn01_primitives.rs
79 lines (72 loc) · 2.48 KB
/
n01_primitives.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use bitris::macros::piece;
use bitris::prelude::*;
fn main() {
// Make pieces
let piece1 = Piece { shape: Shape::T, orientation: Orientation::North };
let piece2 = Piece::new(Shape::T, Orientation::North);
let piece3 = Shape::T.with(Orientation::North);
let piece4 = piece!(TN);
assert!(piece1 == piece2 && piece2 == piece3 && piece3 == piece4);
// Make cc placements
// ..........
// ..#.......
// .#@#...... << @ is cc(2,2)
// ..........
// ..........
let cc1 = CcPlacement {
piece: Piece::new(Shape::T, Orientation::North),
position: CcPosition { cx: 2, cy: 2 },
};
let cc2 = CcPlacement { piece: piece!(TN), position: cc(2, 2) };
assert_eq!(cc1, cc2);
// The placements can be interconverted.
// ..........
// ..#.......
// .@##...... << @ is bl(1,2)
// ..........
// ..........
let bl1 = BlPlacement {
piece: Piece::new(Shape::T, Orientation::North),
position: BlPosition { lx: 1, by: 2 },
};
let bl2 = BlPlacement { piece: piece!(TN), position: bl(1, 2) };
assert_eq!(bl1, bl2);
assert_eq!(bl1.to_cc_placement(), cc1);
assert_eq!(cc1.to_bl_placement(), bl1);
// ..........
// ..#@......
// .###...... << @ is tr(3,3)
// ..........
// ..........
let tr1 = TrPlacement {
piece: Piece::new(Shape::T, Orientation::North),
position: TrPosition { rx: 3, ty: 3 },
};
let tr2 = TrPlacement { piece: piece!(TN), position: tr(3, 3) };
assert_eq!(tr1, tr2);
assert_eq!(tr1.to_cc_placement(), cc1);
assert_eq!(cc1.to_tr_placement(), tr1);
// The placements can be rotated.
// ..........
// ..#.......
// ..@#...... << @ is cc
// ..#.......
// ..........
let north = piece!(TN).with(cc(2, 2));
assert_eq!(north.rotate(Rotation::Cw), piece!(TE).with(cc(2, 2)));
// Note that the position changes except for cc.
// .......... ..........
// ..#....... ..#.......
// .@##...... => ..##...... << @ is bl
// .......... ..@.......
// .......... ..........
let north = piece!(TN).with(bl(1, 2));
assert_eq!(north.rotate(Rotation::Cw), piece!(TE).with(bl(2, 1)));
// .......... ..........
// .......... ..#@......
// .##@...... => ..##...... << @ is tr
// ..#....... ..#.......
// .......... ..........
let south = piece!(TS).with(tr(3, 2));
assert_eq!(south.rotate(Rotation::Ccw), piece!(TE).with(tr(3, 3)));
}