0% found this document useful (0 votes)
31 views4 pages

A* Algorithm Maze Solver Assignment

This assignment requires the implementation of the A* algorithm to solve a maze represented as a 2D grid. Students must create a MazeSolver class with specific methods to navigate the maze, calculate costs, and apply the Euclidean distance heuristic. Submissions must include a Jupyter notebook with the implementation and a PDF report documenting the process, with penalties for late or plagiarized work.

Uploaded by

faisalazeem614
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views4 pages

A* Algorithm Maze Solver Assignment

This assignment requires the implementation of the A* algorithm to solve a maze represented as a 2D grid. Students must create a MazeSolver class with specific methods to navigate the maze, calculate costs, and apply the Euclidean distance heuristic. Submissions must include a Jupyter notebook with the implementation and a PDF report documenting the process, with penalties for late or plagiarized work.

Uploaded by

faisalazeem614
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment # 2

Course: CS-465 Artificial Intelligence Lab


Marks: 30
Due: 17-12-2025

Instructor: Abdul Rehman

Instructions: Please Read Carefully!


This is an individual assignment. Everyone is expected to complete the given
assignment on their own, without seeking any help from any website or any other
individual. There will be strict penalties for any work found copied from any source and
the university policy on plagiarism will be strictly enforced.
Assignment is to be submitted in reply to the assignment posted on the LMS.
Late submissions will have penalty.
Implementation of A* Algorithm for Maze Solver

Introduction:
A maze solver is a path-finding problem, where the goal is to navigate from a starting point
to a goal through a maze. One of the most effective algorithms for solving such problems is
the A* algorithm, which combines heuristic methods and path cost calculations to find the
shortest path efficiently.
In this task, you will implement the A* algorithm to solve a given maze represented as a 2D
grid where:

• 'S' represents the starting position


• 'G' represents the goal position
• '#' represents walls/obstacles
• Empty spaces represent valid paths

The maze to solve is:

Your task is to compute the shortest path and display it on the maze.

Objectives:

Understand the A* Algorithm where:

• Path Cost (g): The cost to reach a given point.


• Heuristic (h): An estimate of the cost from the current point to the goal.
• Evaluation Function (f = g + h): Combines path cost and heuristic to prioritize
exploration.

Before implementing the Algorithm:

• Define the state space, possible actions, and costs.


• Use Euclidean distance as the heuristic.
• Mark the Path on the Maze with the shortest path using a marker such as '.'
1. Movement Costs

Implement the following movement costs:

• Regular moves (up, down, left, right): cost = 1.0


• Diagonal moves (up-left, up-right, down-left, down-right): cost = 1.7

2. Class Implementation:
Create a class MazeSolver that inherits from SearchProblem with the
following methods:
a) init (self, board)
• Note: A init is a constructor in Python that is automatically called
when an object is created. Its primary purpose is to initialize the object's
attributes. Unlike other languages (e.g., Java or C++), Python does not
support constructor overloading. This means that a class cannot have
multiple init methods with different arguments.

• Initialize your maze i.e. set up the maze board and locate both the
starting and goal positions.

b) actions (self, state)

• Return list of valid actions from current state


• Check if resulting positions are within bounds and not walls

c) result (self, state, action)

• Implement state transitions for each action


• Return new state (x, y) coordinates after taking an action

d) is_goal (self, state)

• Check if current state is the goal state

e) cost (self, state, action, new_state)


• Return the cost of taking an action
• Use the predefined COSTS dictionary

f) heuristic (self, state)


• Implement Euclidean distance heuristic
• Calculate straight-line distance from current state to goal
Important:

• The heuristic function must use Euclidean distance (straight-line distance)


between current position and goal.

• The solution should find the optimal path considering both regular and diagonal
movements.

Submission Guidelines:

Submit 2 files. One containing a jupyter notebook file which shall contain the complete
implementation and a PDF of your jupyter notebook with outputs clearly displayed
and a report with proper documentation explaining the logic and steps you followed
for solving each task.

CLO Used:

Implement Python Programming concepts, AI Algorithms, (CLO3) (PLO5)


Machine Learning Models and Natural Language Processing
Techniques.

END OF ASSIGNMENT

You might also like