@@ -19,7 +19,76 @@ TODO: 是否满足容许性?
19
19
###########
20
20
```
21
21
22
+ TODO: 说明隧道中可以停放一个箱子, 在隧道的入口处, 或出口前. 但应该只停靠在入口处, 因为这样更高效. 说明为何更高效.
23
+
24
+ 若推动后产生了如下的模式, 包括旋转和镜像.
25
+
22
26
``` txt
23
- #@ #@#
24
- # # # #
27
+ #$ #$#
28
+ #@# #@#
29
+ ```
30
+
31
+ ``` rs
32
+ impl Solver {
33
+ fn calculate_tunnels (& self ) -> HashSet <(Vector2 <i32 >, Direction )> {
34
+ let mut tunnels = HashSet :: new ();
35
+ for x in 1 .. self . map. dimensions (). x - 1 {
36
+ for y in 1 .. self . map. dimensions (). y - 1 {
37
+ let box_position = Vector2 :: new (x , y );
38
+ if ! self . map[box_position ]. intersects (Tiles :: Floor ) {
39
+ continue ;
40
+ }
41
+
42
+ for (up , right , down , left ) in [
43
+ Direction :: Up ,
44
+ Direction :: Right ,
45
+ Direction :: Down ,
46
+ Direction :: Left ,
47
+ ]
48
+ . into_iter ()
49
+ . circular_tuple_windows ()
50
+ {
51
+ let player_position = box_position + & down . into ();
52
+
53
+ // .
54
+ // #$#
55
+ // #@#
56
+ if self . map[player_position + & left . into ()]. intersects (Tiles :: Wall )
57
+ && self . map[player_position + & right . into ()]. intersects (Tiles :: Wall )
58
+ && self . map[box_position + & left . into ()]. intersects (Tiles :: Wall )
59
+ && self . map[box_position + & right . into ()]. intersects (Tiles :: Wall )
60
+ && self . map[box_position ]. intersects (Tiles :: Floor )
61
+ && self
62
+ . lower_bounds ()
63
+ . contains_key (& (box_position + & up . into ()))
64
+ && ! self . map[box_position ]. intersects (Tiles :: Goal )
65
+ {
66
+ tunnels . insert ((player_position , up ));
67
+ }
68
+
69
+ // . .
70
+ // #$_ or _$#
71
+ // #@# #@#
72
+ if self . map[player_position + & left . into ()]. intersects (Tiles :: Wall )
73
+ && self . map[player_position + & right . into ()]. intersects (Tiles :: Wall )
74
+ && (self . map[box_position + & right . into ()]. intersects (Tiles :: Wall )
75
+ && self . map[box_position + & left . into ()]. intersects (Tiles :: Floor )
76
+ || self . map[box_position + & right . into ()]. intersects (Tiles :: Floor )
77
+ && self . map[box_position + & left . into ()]. intersects (Tiles :: Wall ))
78
+ && self . map[box_position ]. intersects (Tiles :: Floor )
79
+ && self
80
+ . lower_bounds ()
81
+ . contains_key (& (box_position + & up . into ()))
82
+ && ! self . map[box_position ]. intersects (Tiles :: Goal )
83
+ {
84
+ tunnels . insert ((player_position , up ));
85
+ }
86
+ }
87
+ }
88
+ }
89
+ tunnels
90
+ }
91
+
92
+ // ... SKIP...
93
+ }
25
94
```
0 commit comments