CSE 101 -- Prog 5

Due Noon, Monday, December 6th, 2021.

Late submissions will not be accepted/graded.


Objectives:

Description:

Path finding is a common issue in multiple domains, including google maps, graph theory and games. You will be exploring path finding in mazes.

You will be using an adjacency list to store edges between nodes. A maze will consist of a grid, where each vertex is adjacent to the vertices directly, above, below, to the left and to the right.

Graph ADT

The graph ADT is defined in Graph.h, and all functions from Graph.h should be implemented in Graph.c. The graph is implemented as an unweighted adjacency list, which uses an array of linked lists to store the neighbouring nodes for each node.

BFS

The search algorithm you will be implementing is breadth first search. You will be provided a start point, and a target end point. You need to find the distance of the shortest path between them. Additionally, you should report the number of left, right, up and down steps taken.

20 bonus points: A*

For bonus points, you can implement A* as a secondary path finding algorithm.
A* is a best-first, heuristic based path searching algorithm that is comonly used in games. It guarantees to find the shortest path between 2 points, given an admissable heuristic.

An admissable heuristic is one that satisfies the equation `Heuristic(node, target) <= Distance(node, target)`, where Distance(node, target) is the true minimal path distance between the node and the target. In simpler terms: the heuristic function must always be less than or equal to the true path length between 2 points to be admissable.
The heuristic you will use for this program is the Manhattan distance.
Manhatan distance is defined as: `d(x1, y1, x2, y2) = abs(x2 - x1) + abs(y2 - y1)`.

Assumptions and simplifications

Input

You will be provided input via stdin, with the algorithm to use being passed in through a command line argument.

Your program should be able to be executed such that: `./prog5 bfs < maze1.in` will run the program with the BFS algorithm
And: `./prog5 astar < maze1.in` will run the program with the A* algorithm

The input via stdin will consists of 3 sections:
The file will start with the line "======= Nodes ======="
List of nodes, one per line in the form: `x y`.
Line consisting of: "======= Edges ======="
List of undirected edges, one per line in the format: `node_idx_1 node_idx_2`
Line consisting of: "======= Find paths ======="
One path per line in the format: `start_node_idx end_node_idx`

Output

You will output to stdout.
For each line specifying a path to find, print a line of the following format:
`number_explored path_length left_steps right_steps up_steps down_steps`

Where number_explored is the total number of nodes that were explored using the pathfinding algorithm,
path_length is the total length of the path,
left_steps is the number of left neighours followed,
right_steps is the number of right neighbors followed,
up_steps is the number of up neighbors followed,
down_steps is the number of down neighbors followed.

The grid is defined using the same method as Cairo uses, with the origin being in the top left corner, with x increasing to the right and y increasing down. Therefore, up_steps will be the number of times the neighbour node had a smaller y value.

Example input/output

For the following maze, the input and output files are listed below.
                                                              
           ################################                   
           #e.................e...........#                   
           ##############################.#                   
      #####       #.......#     ######  #.##        #####     
      #s..#########.......#######....# ##..#        #...#     
      #...#......##..................###...#####    #...#     
      #...#....................................######...#     
      #...#......######.................................#     
      #.......................s.......e.............#...#     
      #...................s..................#......#...#     
      #################...###########...................#     
                      #...#         ######...#......#####     
                      #####              #...########         
                                         #####                
  


Files for this program:

Resources

Grading:


Last modified Tuesday, 30-Nov-2021 02:24:44 PST.