1- use snk_grid:: { color:: Color , grid:: Grid , point:: Point , snake:: Snake4 } ;
1+ use snk_grid:: {
2+ color:: Color , grid:: Grid , grid_samples:: get_grid_sample, point:: Point , snake:: Snake4 ,
3+ } ;
24
35use crate :: { cost:: Cost , exit_grid:: ExitGrid , snake_path_to_outside:: get_snake_path_to_outside} ;
46
@@ -9,13 +11,8 @@ pub struct Tunnel {
911 pub out_cost : Cost ,
1012}
1113
12- // pub fn get_collect_cost_(is_outside: F, get_cost: C) -> CollectionCost
13- // where
14- // F: Fn(Point) -> bool,
15- // F: Fn(Point) -> u32,
16- // {
17- // }
18-
14+ ///
15+ /// it's not accurate and might report worse tunnel
1916pub fn get_best_tunnel_to_collect_point (
2017 grid : & Grid < Color > ,
2118 exit_grid : & ExitGrid ,
149146
150147 assert_eq ! ( grid. get_color( Point { x: 6 , y: 3 } ) , Color :: Color1 ) ;
151148
152- let pto = ExitGrid :: create_from_grid_color ( & grid) ;
149+ let exit_grid = ExitGrid :: create_from_grid_color ( & grid) ;
150+
151+ let tunnel = get_best_tunnel_to_collect_point ( & grid, & exit_grid, Point { x : 6 , y : 3 } ) ;
152+ assert_eq ! ( tunnel. in_cost. get_color_count( Color :: Color4 ) , 1 ) ;
153+ assert_eq ! ( tunnel. out_cost. get_color_count( Color :: Color4 ) , 0 ) ;
154+
155+ assert_eq ! ( tunnel. in_cost. get_color_count( Color :: Color1 ) , 1 ) ;
156+ assert_eq ! ( tunnel. out_cost. get_color_count( Color :: Color1 ) , 0 ) ;
157+ }
158+
159+ #[ test]
160+ fn it_should_get_snake_path_to_outside_3 ( ) {
161+ let grid = get_grid_sample ( snk_grid:: grid_samples:: SampleGrid :: Caves ) ;
162+
163+ assert_eq ! ( grid. get_color( Point { x: 29 , y: 3 } ) , Color :: Empty ) ;
164+ assert_eq ! ( grid. get_color( Point { x: 29 , y: 4 } ) , Color :: Color4 ) ;
165+
166+ let exit_grid = ExitGrid :: create_from_grid_color ( & grid) ;
167+
168+ let tunnel = get_best_tunnel_to_collect_point ( & grid, & exit_grid, Point { x : 29 , y : 3 } ) ;
169+
170+ println ! ( "{:?}" , tunnel) ;
153171
154- let tunnel = get_best_tunnel_to_collect_point ( & grid, & pto, Point { x : 6 , y : 3 } ) ;
155172 assert_eq ! ( tunnel. in_cost. get_color_count( Color :: Color4 ) , 1 ) ;
156173 assert_eq ! ( tunnel. out_cost. get_color_count( Color :: Color4 ) , 0 ) ;
157174
0 commit comments