@@ -6,22 +6,34 @@ mod snake_compact;
66mod snake_walk;
77mod solver;
88
9+ use std:: collections:: HashSet ;
10+
911use astar:: get_path;
1012use astar_snake:: get_snake_path;
1113use grid:: { Cell , Grid , Point , WalkableGrid } ;
1214use js_sys;
15+ use log:: info;
1316use snake_walk:: get_path_to_eat_all;
1417use solver:: get_free_cells;
1518use wasm_bindgen:: prelude:: * ;
1619
20+ #[ wasm_bindgen]
21+ pub fn init_panic_hook ( ) {
22+ console_error_panic_hook:: set_once ( ) ;
23+ }
24+
1725#[ wasm_bindgen]
1826extern "C" {
1927 fn alert ( s : & str ) ;
2028}
2129
2230#[ wasm_bindgen]
2331pub fn greet ( ) {
24- alert ( "Hello, wasm-game-of-life!" ) ;
32+ init_panic_hook ( ) ;
33+ console_log:: init_with_level ( log:: Level :: Debug ) . unwrap ( ) ;
34+
35+ info ! ( "It works!" ) ;
36+ // alert("Hello, wasm-game-of-life!");
2537}
2638
2739#[ wasm_bindgen]
@@ -122,7 +134,7 @@ type ISnake = Vec<IPoint>;
122134pub fn iget_free_cells ( grid : & IGrid ) -> js_sys:: Uint8Array {
123135 let g = Grid :: from ( grid. clone ( ) ) ;
124136
125- let ( _ , out ) = get_free_cells ( & g, Cell :: Color1 ) ;
137+ let ( out , _ ) = get_free_cells ( & g, Cell :: Color1 ) ;
126138
127139 let o: Vec < u8 > = out. iter ( ) . flat_map ( |p| [ p. x as u8 , p. y as u8 ] ) . collect ( ) ;
128140
@@ -172,9 +184,14 @@ pub fn ieat_free_cells(grid: &IGrid, snake: ISnake) -> Vec<IPoint> {
172184 let grid = WalkableGrid :: create ( Grid :: from ( grid. clone ( ) ) , Cell :: Color1 ) ;
173185 let snake: Vec < Point > = snake. iter ( ) . map ( Point :: from) . collect ( ) ;
174186
175- let ( free_cells, out) = get_free_cells ( & grid. grid , Cell :: Color1 ) ;
187+ let ( free_cells, _) = get_free_cells ( & grid. grid , Cell :: Color1 ) ;
188+
189+ let mut to_eat: HashSet < Point > = HashSet :: new ( ) ;
190+ to_eat. insert ( Point { x : 6 , y : 6 } ) ;
191+ to_eat. insert ( Point { x : 5 , y : 0 } ) ;
176192
177- let path = get_path_to_eat_all ( & grid, & snake, free_cells) ;
193+ let path = get_path_to_eat_all ( & grid, & snake, & to_eat) ;
194+ // let path = get_path_to_eat_all(&grid, &snake, &free_cells);
178195
179196 path. iter ( ) . map ( IPoint :: from) . collect ( )
180197}
0 commit comments