AI Assiggnment Afrar
AI Assiggnment Afrar
Acknowledgment
I would like to express my sincere gratitude to my professor, Mr. Pushpika Prasad for his
guidance and support throughout this assignment. He provided me with valuable feedback and
suggestions that helped me improve my work and learn new skills.
Contents
Acknowledgment ............................................................................................................................ 2
1. Correct initial state................................................................................................................... 4
2. Python code ............................................................................................................................. 4
3. Executing the python code ...................................................................................................... 7
4. Final result ............................................................................................................................... 8
5. explanation of the chosen heuristic function ........................................................................... 9
1. Correct initial state
In this assignment, the initial state is not working properly; it is looping. Therefore, I
edited the code as shown below.
1 2 3
8 0 4
5 6 7
2. Python code
By adding up the horizontal and vertical distances between each tile's current position
and its goal position, the Manhattan distance heuristic calculates the cost of moving from
the current state to the goal state in the context of the 8-puzzle.
The formula for the Manhattan distance between two points (x1, y1) and (x2, y2) is given
by:
The heuristic function in the 8-puzzle adds up the Manhattan distances for every tile, with
the exception of the blank tile, which is represented by the number 0. Because it never
overestimates the actual cost to achieve the goal, this offers an accepted heuristic.
Furthermore, it is consistent, which means that the heuristic value of a node is less than or
equal to the total cost of contacting all neighbors plus their respective heuristic values.
The Manhattan distance heuristic directs the A* algorithm to investigate routes that have
a higher probability of leading to the ideal answer. Because of its effectiveness and
simplicity, it is frequently utilized in grid-based pathfinding issues.