@@ -31,22 +31,25 @@ def test_maze_1(self):
31
31
self .assertTrue ( solution == my_solution )
32
32
33
33
34
- def test_2 (self ):
34
+ def test_weights_instead_of_walls (self ):
35
35
maze = GridWithWeights (4 ,4 )
36
36
walls = []
37
37
maze .walls = walls
38
- weights = {( 0 , 0 ): 3 , ( 0 , 1 ): 1 , ( 1 , 1 ): 4 , (2 , 1 ): 5 ,( 3 , 1 ): 1 ,( 0 , 2 ): 2 , (1 ,2 ): 3 , ( 2 , 2 ): 3 , ( 3 , 2 ): 2 }
38
+ weights = { ( 1 , 1 ): 300 , (1 , 2 ): 300 , (1 ,3 ): 300 }
39
39
maze .weights = weights
40
40
41
- start = (0 ,1 )
42
- end = (3 ,1 )
41
+ start = (0 ,3 )
42
+ end = (3 ,3 )
43
43
44
+ my_solution = [(3 , 3 ), (2 , 3 ), (2 , 2 ), (2 , 1 ),
45
+ (2 , 0 ), (1 , 0 ), (0 , 0 ), (0 , 1 ),
46
+ (0 , 2 ), (0 , 3 )]
44
47
# Call the A* algorithm and get the frontier
45
48
frontier = a_star .a_star_search (graph = maze , start = start , end = end )
46
- maze .draw (width = 3 , point_to = frontier .visited , start = start , goal = end )
47
- maze .draw (width = 3 , number = frontier .costs , start = start , goal = end )
48
- print (frontier .visited )
49
49
50
+ solution = list (backtrack (frontier .visited ,start ,end ))
51
+
52
+ self .assertTrue ( solution == my_solution )
50
53
51
54
if __name__ == "__main__" :
52
55
unittest .main ()
0 commit comments