You are on page 1of 73

Experiment 01

AIM: Installation of Python

History of Python
Python is a widely used general-purpose, high-level programming language. It was initially
designed by Guido van Rossum in 1991 and developed by Python Software Foundation. It was
mainly developed for emphasis on code readability, and its syntax allows programmers to express
concepts in fewer lines of code.
In the late 1980s, history was about to be written. It was that time when working on Python started.
Soon after that, Guido Van Rossum began doing its application-based work in December of 1989
at Centrum Wiskunde & Informatica (CWI) which is situated in the Netherlands. It was started
firstly as a hobby project because he was looking for an interesting project to keep him occupied
during Christmas. The programming language in which Python is said to have succeeded is ABC
Programming Language, which had interfacing with the Amoeba Operating System and had the
feature of exception handling. He had already helped to create ABC earlier in his career and he
had seen some issues with ABC but liked most of the features. After that what he did was really
very clever. He had taken the syntax of ABC, and some of its good features. It came with a lot of
complaints too, so he fixed those issues completely and had created a good scripting language that
had removed all the flaws. The inspiration for the name came from BBC’s TV Show – ‘Monty
Python’s Flying Circus’, as he was a big fan of the TV show and also, he wanted a short, unique
and slightly mysterious name for his invention and hence he named it Python.

Versions of Python
Version Release Date Important Features
Python 0.9.0 February 1991 • Classes with inheritance exception
handling
• Functions
• Modules

Python 1.0 January 1994 • Functional programming tools (lambda,


map, filter and reduce).
• Support for complex numbers.
• Functions with keyword arguments

Python 2.0 October 2000 • List comprehension.


• Cycle-detecting garbage collector.
Python 2.7.0 - EOL - July 2010 • Support for Unicode. Unification of data
Jan 2020 types and classes

Nitin Kumar 1 A20405220040


Python 3 December 2008 • Backward incompatible.
• print keyword changed to print() function
Python 3.6 December 2016 • raw_input() function depreciated
Python 3.6.5 March 2018 • Unified str/Unicode types.
• Utilities for automatic conversion of
Python 2.x code

Python 3.7.0 May 2018 • New C API for thread-local storage


• Built-in breakpoint()
• Data classes
• Context variables

Python 3.8 October 2019 • Assignment Expression


• Positional-only parameters
• Parallel filesystem cache for compiled
bytecode files

Python 3.9 - Current October 2020 • Dictionary Merge & Update Operators
Version • New removeprefix() and removesuffix()
string methods
• Builtin Generic Types

Nitin Kumar 2 A20405220040


Figure 1 Python Versions

Compilers of python:
Online Python Compiler:
Advantages:
1. Accessibility: Online Python compilers can be accessed from any device with an internet
connection, making it convenient for users who don't have Python installed locally or need to code
on the go.
2. No installation required: Users don't need to install Python or any related libraries on their local
machine, which reduces setup time and potential conflicts between different versions of Python.
3. Collaboration: Online compilers often allow users to share code snippets easily, making it
convenient for collaboration and troubleshooting.

Nitin Kumar 3 A20405220040


4. Platform independence: Online compilers work across different operating systems, making them
accessible to users regardless of their system.

Disadvantages:
1. Internet dependency: Online compilers require an internet connection to function. If the internet
is slow or unavailable, it can hinder the development process.
2. Privacy concerns: Some online compilers may store code snippets temporarily, potentially
raising concerns about data privacy and security.
3. Limited resources: Online compilers may have limitations on execution time, memory usage, or
access to certain Python modules or libraries, which could be restrictive for complex projects.

Offline Python Compiler:


Advantages:
1. No internet dependency: An offline Python compiler doesn't require an internet connection,
ensuring that you can work on your code even in areas with limited or no internet access.
2. Full control over resources: When using an offline compiler, you have more control over the
system's resources, including memory and execution time.
3. Privacy and security: Since you are running the compiler locally, you have more control over
your code's privacy and security.
4. Greater flexibility: Offline compilers allow you to use any Python libraries or modules installed
on your system, providing more flexibility in development.

Disadvantages:
1. Installation and setup: Users need to install Python and any necessary libraries on their local
machine, which might require some technical knowledge and time.
2. Platform compatibility: An offline compiler may have issues running on different operating
systems, potentially leading to compatibility problems.
3. Collaboration challenges: Sharing code from an offline compiler might involve manually
sharing files, which can be less efficient than the collaborative features of online compilers.

In summary, choosing between an online and offline Python compiler depends on your specific
needs and circumstances. If you prioritize accessibility, collaboration, and don't want to deal with

Nitin Kumar 4 A20405220040


installation issues, an online compiler might be the right choice. On the other hand, if you need
greater control over resources, privacy, and prefer working offline, an offline compiler would suit
you better.

1. Offline Compilers:
PyDev
Eclipse is an IDE best for Java language. Still, thanks to a system of extensions and plugins. We
can use more languages to compile and run in Eclipse itself. PyDev is also one of the plugins that
Eclipse can use as a Python IDE.
There are some interesting features to know about PyDev:
• It provides good support for Python Web Development.
• It has a good syntax highlighting and remote debugger.
• It also has an interactive console.
• It is easy to learn and has several features like CPython and Jython.
• It offers error phasing and folding of codes that are useful for devs.

PyCharm
PyCharm is one of the best python compilers as it is used by most professional python developers.
PyCharm is developed by JetBrains. It gives a variety of tools, modules, and packages to speed up
Python development.
Some features of PyCharm include:
• It offers more than 1000 plugins.
• PyCharm supports smart code navigation.
• You can increase productivity by using the customizable interface feature.
• It has a fast and safe refactoring tool.
• It offers Live Code Verification along with Syntax Highlighting.

Jupyter Notebook
Jupyter Notebook is an IDE mostly used for Data Science environments in python. It is developed
by Fernando Pérez and Brian Granger. It is a free IDE, so everyone can use it while compiling any
python codes.
The most notable features of the Jupyter Notebook are:
• It allows you to use data visualization tools like Numpy, Seaborn, and Matplotlib.
• User can export the task in multiple formats such as CSV, pdf, Html, etc.

Nitin Kumar 5 A20405220040


• It has a starting and stopping server option so you can continue your work or pause at any
time.
• It combines the text, images, and code for a greater user experience.
• It allows you to see and edit your code to make it more catchy.

Atom
Atom is also one of the best python compilers that are flexible and easy to use. It is developed by
GitHub. Also, you can use Atom on different platforms like Windows, Linux, and macOS.
Let's now discuss some of its features:
• Users can install and manage packages on their own.
• It also gives you the git integration.
• It supports a large number of plugins.
• You can give custom commands to the compiler for better interaction.
• Smart auto-completion.

Spyder
Spyder is another python IDE that is free and easy to use. It is developed by Pierre Raybaut. It
supports multiple platforms like Windows, Linux, and Mac. Let's discuss some features of Spyder.
• Users can explore and edit the variables using GUI.
• Users can view any object documents instantly and modify the document.
• It has a strong debugger.
• It improves the coding experience by giving a variety of options in plugins.
• It has quality community support.
IDLE
IDLE is a highly regarded and advised IDE for educational purposes because of its simplicity. As
earlier said, IDLE is a very simple and powerful IDE designed mainly for beginners.
Some of the exciting features to know about IDLE:
• This IDE is suitable for developers at the beginning level.
• The capacity to look for multiple files.
• An interactive interpreter that highlights syntax and shows error and I/O messages.
• Along with regular text editor features and smart indenting.
• An extremely capable debugger.

Nitin Kumar 6 A20405220040


Sublime Text
Sublime text is a cross-platform shareware source code editor. Many markups and programming
languages are supported natively. Users can increase its value by adding plugins, which are
developed and maintained by the community under free software licenses. A Python API is
available in Sublime Text to help with plugins.

Features of sublime text:


• API for Python-based Plugins.
• preferences particular to a project.
• JSON settings files allow for extensive modification, including platform- and project-
specific options.
• Cross-platform and supportive plugins for cross-platform (Windows, macOS, and Linux).
• Quick access to project files, symbols, or lines with "Goto Anything".

Vim
An open-source and free text and source code editor is called Vim. It comes with inbuilt Git
Control. You have to install Vim in Windows, but for UNIX and macOS, it is already installed.
There is a big list of plugins in Vim.
Let's know about the Features of Vim:
• It has a powerful search engine.
• It supports many different plugins.
• Lightweight app.
• It is very stable while running code.
• Cross-platform development assistance.
Visual Studio Code
Microsoft made the source-code editor Visual Studio Code. It is also known as VS Code. VS Code
is supported in Windows, Linux, and macOS using the Electron Framework. The features are
debugging help, syntax highlighting, smart code completion, snippets, code refactoring, and
integrated Git.
Essential Features of VS Code:
• With its robust command line interface, Visual Studio Code gives you complete control
over how the editor opens.
• Git integration is inbuilt into Visual Studio Code. This allows you to push, pull, and commit
changes to your code to a remote Git repository.
• With all UI except the editor hidden in VSCode's Zen Mode, you can concentrate on writing
code.

Nitin Kumar 7 A20405220040


• Keyboard shortcuts can display errors and warnings for users.
• Based on many factors, one of the most excellent smart code completion systems.

2. Online Compilers
Programiz
Programiz provides a free Python online compiler and interpreter that allows users to write,
compile, and execute Python code directly from their web browser. It provides a clean UI which
will help you execute your basic python codes.

TutorialsPoint
Tutorialspoint Python compiler is a simple yet powerful tool that supports Python 2 and Python 3.
It has a clean and intuitive interface, making it easy to use even for beginners. The compiler also
provides features like syntax highlighting, auto-indentation, and code completion, which can help
streamline the coding process.

Scalar
Scalar is a web-based code editor that supports several programming languages, including Python.
It provides a real-time compiler and debugger and allows you to collaborate with others.

Replit
Replit is an online platform that serves as a compiler, IDE, interpreter, and editor. It enables users
to write code, run, share, collaborate, and execute Python through your browser.

Replit Features
• GitHub integration
• Support for 50+ programming languages
• Use it from any computer that is connected to the internet and can and run a web browser
• Collaborate with your friends in real-time with the Multiplayer feature
• Collaborate with your coworkers with the Teams feature
• Use Replit on any operating system including macOS, Windows, and Linux
• Quickly start your projects with the Hosting feature

Nitin Kumar 8 A20405220040


• Join the global community of coders – beginners and experts
• Deploy any Python code to the public in one click
Replit Pricing
The Starter plan with the following features is free. There are two more paid plans, named Hacker
and Teams.
Starter Plan Features
• Multiplayer collaboration
• Storage 500 MB
• Memory 500 MB
• 2 – 0.5 vCPUs

Python.org
Python.org is Python’s official website. It has an online Python shell provided
by PythonAnyWhere. You can execute the Python code in the interactive shell. You will get access
to machines with a full Python environment already installed and develop or execute code directly
from your browser without installing software.

w3school
W3Schools is a popular online learning platform that offers a web-based IDE for Python
programming. It provides a simple interface and allows you to write and test your Python code
online.

Jdoodle
JDoodle is another popular online code editor and compiler that supports several programming
languages, including Python. It has a clean and easy-to-use interface and provides a real-time
compiler and debugger.

Python version used for AI:


• Python 3 improves AI, machine learning, and data science support. It has more updates
that Python 2 does not have.
• Python 3 is still supported and has a large user base to help with support, whereas Python
2 was discontinued in 2020.

Nitin Kumar 9 A20405220040


Difference between python 2 and 3
Comparison Python 2 Python 3
Parameter
Year of Release Python 2 was released in the year Python 3 was released in the year
2000. 2008.
“Print” In Python 2, print is considered to be In Python 3, print is considered to be a
Keyword a statement and not a function. function and not a statement.
Storage of In Python 2, strings are stored as In Python 3, strings are stored as
Strings ASCII by default. UNICODE by default.
Division of On the division of two integers, we On the division of two integers, we get
Integers get an integral value in Python 2. a floating-point value in Python 3. For
For instance, 7/2 yields 3 in Python instance, 7/2 yields 3.5 in Python 3.
2.
Exceptions In Python 2, exceptions are enclosed In Python 3, exceptions are enclosed
in notations. in parentheses.
Variable The values of global variables do The value of variables never changes
leakage change in Python 2 if they are used in Python 3.
inside a for-loop.
Iteration In Python 2, the xrange() function In Python 3, the new Range() function
has been defined for iterations. was introduced to perform iterations.
Ease of Syntax Python 2 has more complicated Python 3 has an easier syntax
syntax than Python 3. compared to Python 2.
Libraries A lot of libraries of Python 2 are not A lot of libraries are created in Python
forward compatible. 3 to be strictly used with Python 3.
Usage in Python 2 is no longer in use since Python 3 is more popular than Python
today’s times 2020. 2 and is still in use in today’s times.
Backward Python 2 codes can be ported to Python 3 is not backward compatible
compatibility Python 3 with a lot of effort. with Python 2.
Application Python 2 was mostly used to Python 3 is used in a lot of fields like
become a DevOps Engineer. It is no Software Engineering, Data Science,
longer in use after 2020. etc.

Nitin Kumar 10 A20405220040


System requirements:
o Operating System:
• Windows 7,10 or 11
• Mac OS X 10.11 or higher, 64-bit
• Linux: RHEL 6/7, 64-bit (almost all libraries also work in Ubuntu)
o x86 64-bit CPU (Intel / AMD architecture)
o 4 GB RAM
o 5 GB free disk space

Steps to install python:


1. Visit Anaconda.com/downloads

2. Select Windows

3. Download the .exe installer.

Nitin Kumar 11 A20405220040


4. Open and run the .exe installer.

5. Open the Anaconda Prompt

Nitin Kumar 12 A20405220040


Experiment 02
AIM: Implement Breadth First Search, Depth First Search, Depth Limit
Search Algorithms.

Figure: 2 Tree

Here we have been given a tree which is containing 10 node from A to J. We have to implement
BFS (Breadth First Search), DFS(Depth Limit Search), DLS(Depth Limit Search).

Here the goal node is J and we have to implement above search algorithm to traverse the tree and
find the goal node.

Nitin Kumar 13 A20405220040


1. (A) Breadth First Search Algorithm:
The steps of the algorithm work as follow:
1. Initialize a queue.
2. Enqueue the root node into the queue.
3. While the queue is not empty:
4. Dequeue a node from the front of the queue.
5. Process the node (check if it's the target, perform some action, etc.).
6. Enqueue all of the node's children into the queue.
7. If the target node is found during processing, return it. Otherwise, continue the loop until
the queue is empty.
8. If the target node is not found and the queue becomes empty, terminate the search and
return a failure status or value.

Nitin Kumar 14 A20405220040


(B) Depth First Search Algorithm:
This algorithm performs a depth-first search (DFS) on a binary tree, visiting each node in preorder
(i.e., visiting the root node first, then its left subtree, and finally its right subtree). It searches for a
specific element in the tree and prints 'true' if it finds it.

1. Create a Node class that has three attributes: left, right, and val. The left and right attributes
represent the left and right child nodes of the current node, while the val attribute represents
the value stored in the current node.
2. Define a function called preorder that takes two arguments: root and element. The root
argument represents the root node of the binary tree, while the element argument represents
the value to search for in the tree.
3. In the preorder function, check if the root argument is not None. If it is not, then:
i) Check if the value of the current node (root.val) is equal to the value of the element
argument. If it is, then print 'true'.
ii) Recursively call the preorder function with the left child node (root.left) and the
element argument as arguments.
iii) Recursively call the preorder function with the right child node (root.right) and the
element argument as arguments.
4. Create an instance of the Node class with a value of 1 and assign it to a variable called root.
5. Set the left child node of root to a new instance of the Node class with a value of 2.
6. Set the right child node of root to a new instance of the Node class with a value of 3.
7. Set the left child node of the left child node of root to a new instance of the Node class with
a value of 4.
8. Set the right child node of the left child node of root to a new instance of the Node class
with a value of 5.

Nitin Kumar 15 A20405220040


9. Call the preorder function with arguments root and 3.

Nitin Kumar 16 A20405220040


(C) Depth Limited Search (DLS) Algorithm:
The steps of the algorithm work as follow:

1. The root node is added to the beginning of the stack.


2. Then it is marked as visited, and if root node is not the goal node in the search, then we
push neighbour of root node on top of the stack.
3. Next, we mark it as visited and check if it is the goal node or not.
4. If it is not found to be the goal node, then we push neighbour of that node on top of the
stack.

5. Now we search in the same depth limit and move along depth-wise to check for the goal
nodes.
6. If depth limit is found to be reached, then we retrace back to nearest nodes that remain
unvisited or unexplored.
7. Then we push them into the stack and mark them visited.
8. We continue to perform these steps in iterative ways unless the goal node is reached or
until all nodes within depth limit have been explored for the goal.

Step 1: PUSH starting node A in stack.

Step 2: POP top node A and find its neighbours node i.e. B,C,D.

Step 3: Now node B is on top. So POP B and find its neighbour nodes. i.e. G, H.

Step 4: Now node G is on top. So POP G and we reached limit 2 so we will not check its neighbour
node.

Step 5: Now node H is on top. So POP H and we reached limit 2 so we will not check its neighbour
node.

Step 6: Now node D is on top. So POP D and find its neighbour nodes. i.e. E, F.

Step 7: Now node F is on top. So POP F and we reached limit 2 so we will not check its neighbour
node.

Step 8: Now node E is on top. So POP E and we reached limit 2 so we will not check its neighbour
node.

Step 9: Now node C is on top. So POP C and it has no neighbour node.

Step 10: Now the stack is empty and we have not found goal node so we return false.

Step 11: Exit.

Nitin Kumar 17 A20405220040


Nitin Kumar 18 A20405220040
2. Algorithms with User Input:
(A)Breadth First Search:

Nitin Kumar 19 A20405220040


Nitin Kumar 20 A20405220040
(B) Depth First Search:

Nitin Kumar 21 A20405220040


Nitin Kumar 22 A20405220040
(C) Depth Limit Search:

Nitin Kumar 23 A20405220040


Nitin Kumar 24 A20405220040
Experiment 03
AIM: Implement Monkey Banana Problem
Algorithm:
1. Define a State class to represent the state of the monkey, box, and bananas. The class should include:
- monkey_x, monkey_y: The x and y coordinates of the monkey.
- box_x, box_y: The x and y coordinates of the box.
- actions: A list to store the sequence of actions taken to reach this state.
2. Create an empty set visited to keep track of visited states.
3. Create an empty queue queue and enqueue the initial_state.
4. While the queue is not empty:
a. Dequeue the current_state from the front of the queue.
b. Add the (current_state.monkey_x, current_state.monkey_y, current_state.box_x, current_state.box_y)
tuple to the visited set.
c. Check if the current_state is the goal state (i.e., monkey is at target_x, target_y):
- If it is the goal state, return current_state.actions as the solution.
d. Generate possible actions and their resulting states:
- Possible actions include:
- MoveMonkeyLeft
- MoveMonkeyRight
- MoveBoxLeft
- MoveBoxRight
- ClimbOnBox
- ClimbOffBox
- Calculate the new coordinates for the monkey and the box based on each action.
e. For each possible action:
- Create a new new_state object with the updated coordinates.
- Set new_state.actions to be a copy of current_state.actions with the current action appended.
f. Check if the new state is valid:
- Ensure that the monkey, box, and bananas are within the room boundaries (0-4 in both x and y
coordinates).

Nitin Kumar 25 A20405220040


- Check if (new_monkey_x, new_monkey_y, new_box_x, new_box_y) is not in the visited set.
g. If the new state is valid, enqueue new_state into the queue.
5. If the loop exits without finding a solution, return None to indicate that no solution exists.

Nitin Kumar 26 A20405220040


Nitin Kumar 27 A20405220040
Experiment 04
AIM: Implement Tic Tac Toe Problem
Tic Tac Toe Game Algorithm:

1. Initialize the player (X) and opponent (O) symbols.


2. Create a 3x3 game board filled with empty spaces (' ').
3. Define a function to print the current game board.
4. Define a function to check if a player has won the game by checking rows, columns, and
diagonals.
5. Define a function to check if the game board is full (a draw).
6. Define a function to get the player's move by accepting the row and column input.
7. Implement the Minimax algorithm:
• Define an evaluation function to evaluate the board state.
• Define the Minimax function, which recursively explores all possible moves and
returns the best score.
• The Maximizer tries to maximize the score, and the Minimizer tries to minimize
it.
• The Minimax function keeps track of the best move and its associated score.
8. Define a function to find the best move for the computer using the Minimax algorithm.
Iterate through all possible moves and choose the one with the highest score.
9. Implement the main game loop:
• Display a welcome message.
• Print the initial game board.
• Start a loop to alternate between player and computer turns until the game ends.
• For the player's turn:
▪ Get the player's move (row and column) using user input.
▪ Update the game board with the player's move.
▪ Check if the player has won. If yes, print a victory message and end the
game.
▪ Check if the game board is full (a draw). If yes, print a draw message and
end the game.
• For the computer's turn:
▪ Use the Minimax algorithm to find the best move for the computer.
▪ Update the game board with the computer's move.
▪ Check if the computer has won. If yes, print a victory message and end the
game.
▪ Check if the game board is full (a draw). If yes, print a draw message and
end the game.
10. End the game.

Nitin Kumar 28 A20405220040


Figure 3: Tic Tac Toe

Nitin Kumar 29 A20405220040


Nitin Kumar 30 A20405220040
Nitin Kumar 31 A20405220040
Nitin Kumar 32 A20405220040
Nitin Kumar 33 A20405220040
Experiment 05
AIM: Implement 8 Puzzle Problem
8 Puzzle Problem
A 3 by 3 board with 8 tiles (each tile has a number from 1 to 8) and a single empty space is
provided. The goal is to use the vacant space to arrange the numbers on the tiles such that they
match the final arrangement. Four neighbouring (left, right, above, and below) tiles can be moved
into the available area.

Figure 4: 8 Puzzle Problem


Rules of the 8-puzzle problem:
1. You can only move a tile into the empty space.

2. Tiles can be moved either horizontally or vertically, but only one position at a time.

3. The objective is to reach the goal state from an initial state using the fewest possible moves.

Solving the 8-puzzle problem is often done using search algorithms like A* search or breadth-first
search. Here's a simplified outline of how you can approach solving it using A* search:
1. State Representation: Represent the puzzle's state as a data structure. Typically, this involves a
2D array to represent the tile positions.
2. Define the Heuristic: Choose a heuristic function to estimate how close a state is to the goal state.
Common heuristics include the Manhattan distance (sum of distances each tile is away from its
goal position) and the misplaced tiles count (number of tiles not in their goal positions).
3. Initial State: Start with the initial state of the puzzle.

Nitin Kumar 34 A20405220040


4. Open and Closed Lists: Create two lists, the "open" list (to store states to be explored) and the
"closed" list (to store states already explored).
5.A Search: Use the A search algorithm to explore states. At each step, consider all possible moves
from the current state, evaluate their cost based on the heuristic function, and select the one with
the lowest cost.
6. Repeat Until Goal: Continue exploring states and selecting moves until the goal state is reached
or no more moves are possible.
7. Backtracking: Once the goal state is reached, backtrack from the goal state to the initial state to
find the sequence of moves that solved the puzzle.

Figure 5: 8 Puzzle Problem Tree


1. DFS (Brute - Force) :
On the state-space tree (Set of all configurations of a particular issue, i.e., all states that may be
reached from the beginning state), we can do a depth-first search.
In this solution, further movements might not always send us closer to the objective, but rather
further away. Regardless of the initial state, the state-space tree searches down the leftmost route
from the root. With this method, an answer node might never be discovered.
2. BFS (Brute - Force) :
We can search the state space tree using a breadth-first approach. It always locates the goal state
that is closest to the root. However, the algorithm tries the same series of movements as DFS
regardless of the initial state.
3. Branch and Bound :

Nitin Kumar 35 A20405220040


By avoiding searching in sub-trees which do not include an answer node, an "intelligent" ranking
function, also known as an approximatsion costs function, may frequently speed up the search for
an answer node. However, instead of using the backtracking method, it does a BFS-style search.
Basically, Branch and Bound involves three different kinds of nodes.
1.A live node is a created node whose children have not yet been formed. 2.The offspring of the
E-node which is a live node, are now being investigated. Or to put it another way, an E-node is a
node that is currently expanding. 3.A created node which is not to be developed or examined
further is referred to as a dead node. A dead node has already extended all of its offspring.
Costs function:
In the search tree, each node Y has a corresponding costs. The next E-node may be found using
the costs function. The E-node with the lowest costs is the next one. The function can be defined
as :
1.C(Y) = g(Y) + h(Y)
2.where
3.g(Y) = the costs of reaching to the current node
4.from the root.
5.h(Y) = the costs of reaching to an answer node from the Y.
The optimum costs function for an algorithm for 8 puzzles is : We suppose that it will costs one
unit to move a tile in any direction. In light of this, we create the following costs function for the
8-puzzle algorithm :
1.c(y) = f(y) + h(y)
2.where
3.f(y) = the path's total length from the root y.
4.and
5.h(y) = the amount of the non-blank tiles which are not in
6.their final goal position (misplaced tiles).
7.To change state y into a desired state, there are at least h(y) movements required.
Final algorithm :
1. In order to maintain the list of live nodes, algorithm LCSearch employs the functions Least() and
Add().
2. Least() identifies a live node with the least c(y), removes it from the list, and returns it.

3.Add(y) adds y to the list of live nodes.

Nitin Kumar 36 A20405220040


4. Add(y) implements the list of live nodes as a min-heap.

The route taken by the aforementioned algorithm to arrive at the final configuration of the 8-Puzzle
from the starting configuration supplied is shown in the diagram below. Keep in mind that only
nodes with the lowest costs function value are extended.

Figure 6 8 Puzzle Tree

Nitin Kumar 37 A20405220040


Nitin Kumar 38 A20405220040
Nitin Kumar 39 A20405220040
Nitin Kumar 40 A20405220040
Nitin Kumar 41 A20405220040
Experiment 06
AIM: Implement Tower of Hanoi Problem
The Rule For disk movement in TOH:
The rules according to which the disks have to be moved in Tower of Hanoi are the following:
1. Initially, the disks are placed in Increasing Order in size on Tower 1 from top to bottom.
2. the objective is to move them to tower 2, making also use of an auxiliary tower 3.
3. the conditions for moving the disks are:
4. all disks (except the one to be moved) have to be on one of the three towers.
5. Only one disk is possible to move at a time.
6. The only top disk can be moved i.e. taking from the top of one tower and placing on the
top of another tower.
7. A larger disk can never be placed on a smaller disk.
if we will have n number of disk then our aim is to move bottom which is disk n from source to
destination. And then put all other (n-1) disks onto it.

Steps we will follow are:

Step 1 − Move n-1 disks from source to aux

Step 2 − Move nth disk from source to dest

Step 3 − Move n-1 disks from aux to dest

Figure 7 Tower of Hanoi

Algorithm TowerOfHanoi(n, source, auxiliary, destination):

if n == 1:

Move disk from source to destination

Nitin Kumar 42 A20405220040


return

TowerOfHanoi(n-1, source, destination, auxiliary) // Move n-1 disks from source to auxiliary

Move disk from source to destination // Move the largest disk from source to destination

TowerOfHanoi(n-1, auxiliary, source, destination) // Move n-1 disks from auxiliary to destination

Nitin Kumar 43 A20405220040


Experiment 07
AIM: Implement Water Jug Problem
Algorithm
1. Import the deque class from the collections module.
2. Define the BFS function with parameters a (capacity of Jug1), b (capacity of Jug2), and target
(the target amount to measure).
3. Initialize a dictionary m to keep track of visited states, a boolean variable isSolvable to check if
a solution exists, and an empty list path to store the path from the initial state to the solution state.
4. Create a deque q and enqueue the initial state (0, 0) as a tuple (Jug1's current amount, Jug2's
current amount).
5. Perform a BFS traversal while the queue q is not empty:
a. Dequeue the front element u.
b. Check if the state (u[0], u[1]) has already been visited. If so, continue to the next iteration.
c. Check if the current state is valid (within the jug capacities and non-negative).
d. Add the current state to the path list.
e. Mark the current state as visited in the m dictionary.
f. Check if the target amount is reached in either Jug1 or Jug2. If so, set isSolvable to True and
break from the loop.
g. Enqueue the following states:
- Filling Jug2 to its maximum capacity.
- Filling Jug1 to its maximum capacity.
- Pouring water from Jug2 to Jug1 and vice versa, while maintaining valid states.
- Emptying Jug2 and Jug1 separately.
6. If a solution is found (isSolvable is True), print the path from the initial state to the solution
state.
7. If no solution is found (isSolvable is still False), print "No solution."

Nitin Kumar 44 A20405220040


Nitin Kumar 45 A20405220040
Nitin Kumar 46 A20405220040
Experiment 08
AIM: Implement Travelling Salesman Problem

The traveling salesman problems abide by a salesman and a set of cities. The salesman has to visit
every one of the cities starting from a certain one (e.g., the hometown) and to return to the same
city. The challenge of the problem is that the traveling salesman needs to minimize the total length
of the trip.Suppose the cities are x1 x2 xn where cost cij denotes the cost of travelling from city
xi to xj. The travelling salesperson problem is to find a route starting and ending at x1 that will take
in all cities with the minimum cost.

Algorithm-

• Travelling salesman problem takes a graph G {V, E} as an input and declare another graph
as the output (say G’) which will record the path the salesman is going to take from one
node to another.
• The algorithm begins by sorting all the edges in the input graph G from the least distance
to the largest distance.
• The first edge selected is the edge with least distance, and one of the two vertices (say A
and B) being the origin node (say A).
• Then among the adjacent edges of the node other than the origin node (B), find the least
cost edge and add it onto the output graph.
• Continue the process with further nodes making sure there are no cycles in the output graph
and the path reaches back to the origin node A.
• If the origin is mentioned in the given problem, then the solution must always start from
that node only.

Figure 8 Travelling Sales Man Graph

Nitin Kumar 47 A20405220040


Nitin Kumar A20405220040
Experiment- 9

Aim: Implement Eight Queens Problem


The Eight Queens Problem is a classic puzzle in the field of computer science and mathematics. It's a
chessboard-based problem that challenges you to place eight queens on an 8x8 chessboard in such a way
that no two queens threaten each other. In other words, no two queens can be in the same row, column, or
diagonal.
Here are some key points about the Eight Queens Problem:
Objective: The goal of the problem is to find a way to place eight queens on the chessboard so that none
of them can attack (or threaten) any other queen. This means that no two queens should share the same row,
column, or diagonal.
Rules:
• Queens can move vertically, horizontally, and diagonally on the chessboard.
• The chessboard is an 8x8 grid, so there are eight rows and eight columns.
• Each row can have at most one queen.
• Each column can have at most one queen.
• Each diagonal (both diagonals, left to right and right to left) can have at most one queen
.

Algorithm:
The Eight Queens Problem can be solved using a backtracking algorithm, which systematically explores
different combinations of queen placements while ensuring that no two queens threaten each other. Here's
an in-depth algorithm for solving the Eight Queens Problem:
Algorithm: Backtracking for the Eight Queens Problem
1. Initialize the Chessboard: Create an 8x8 chessboard (represented as a 2D array) and initialize all cells to
empty (0) to represent an empty board.
2. Place Queens (Recursive Function): Define a recursive function, let's call it place Queens(board, row),
where board represents the current state of the chessboard, and row is the current row being considered.

Nitin Kumar A20405220040


Base Case:

Nitin Kumar A20405220040


• If row becomes 8 (meaning all queens are placed successfully), print the solution (the arrangement
of queens) and return.

Recursive Case

For the current row, iterate through each column (from 0 to 7).
• For each column, check if it's safe to place a queen in that cell.
• To check safety, ensure that:
• There is no queen in the same column in any of the previous rows.
• There are no queens on the diagonals (both left and right) in any of the previous rows.
• If it's safe to place a queen in the current cell, mark the cell as a queen (e.g., set it to 1) and move to
the next row by calling placeQueens(board, row + 1) recursively.
• After the recursive call, if it doesn't lead to a valid solution, backtrack by removing the queen from
the current cell (set it back to 0), and continue checking the next column.
• Continue this process recursively for all rows.
3. Start the Algorithm: Call placeQueens(board, 0) to start the algorithm from the first row.
4. Print Solutions: In the placeQueens function, when a valid solution is found (all queens are placed without
conflicts), print the chessboard with queens as the solution.
5. End of Algorithm: The algorithm will continue to explore and backtrack until all possible solutions are
found or exhausted.2. Place Queens (Recursive Function): Define a recursive function, let's call it
placeQueens(board, row), where board represents the current state of the chessboard, and row is the current
row being considered.

Nitin Kumar A20405220040


Code:

A20405220040
Nitin Kumar
Nitin Kumar
Output:

Nitin Kumar A20405220040


Experiment- 10

Aim: To study the available platforms for AI programming.


There are three types of platforms available for AI programming-
A. Python
B. Lisp
C. Prolog

B. Lisp Platform:

● The problems that were faced by the traditional programming languages that lead to the
evolution of Lisp.

Traditional programming languages faced problems like limited flexibility and expressiveness,
which led to the evolution of Lisp. Lisp addressed these issues by introducing a highly flexible
and symbolic approach to programming, making it easier to manipulate code and data.

Drawbacks of Traditional Languages:


Traditional programming languages faced limitations like:

1. Lack of flexibility: They were rigid in expressing algorithms.


2. Limited recursion: Difficulties in handling recursive structures.
3. Poor symbolic manipulation: Inefficient for symbolic data.
4. Absence of dynamic typing: Fixed data types hindered adaptability.

Lisp evolved to address these issues, offering:

1. Symbolic expressions: A versatile data structure.


2. Recursive functions: Simplified handling of complex problems.
3. Dynamic typing: Enhanced adaptability and expressiveness.
4. Robust symbolic manipulation: Improved AI and symbolic computing support.

● The evolution of Lisp-


The evolution of Lisp can be traced through several major versions, each introducing significant
changes and improvements to the language. Lisp has seen several versions and dialects over the
years. Here are some:
1. Lisp 1.5 (1962): One of the earliest and influential versions of Lisp.

2. MacLisp (1966): Developed at MIT, it introduced significant features like the EVAL function.

3. InterLisp (circa 1967): Focused on interactive programming and was used on early personal computers.

4. Scheme (1975): A minimalist dialect emphasizing simplicity and elegance. It influenced the design of other
languages, including Common Lisp.

5. Common Lisp (1984): A standardized version of Lisp that aimed to unify various Lisp dialects. Common Lisp
introduced many features and remains a widely used Lisp dialect.

6. Emacs Lisp: A dialect of Lisp used for extending the Emacs text editor.
Nitin Kumar A20405220040
7. Clojure (2007): A modern Lisp dialect that runs on the Java Virtual Machine (JVM) and emphasizes functional
programming and immutability.

Nitin Kumar A20405220040


8. Racket (formerly PLT Scheme): A dialect of Lisp primarily used for research and education in programming
languages.

9. AutoLisp: A dialect of Lisp used for extending AutoCAD, a popular computer-aided design software.

10. Dylan (circa 1992): A dynamically typed, multi-paradigm language with Lisp roots.

11. NewLISP: A scripting language and dialect of Lisp designed for practical use and ease of integration.

12. Picolisp: A minimalistic and lightweight Lisp dialect with a unique data structure called "Pilog" for representing
facts.

The problem domain of AI lab and the library which will be used and their distribution.

The problem domain of an AI lab encompasses the study and development of artificial intelligence
(AI) technologies and applications. It involves creating algorithms, models, and systems that mimic
human intelligence and behavior, enabling computers to perform tasks that typically require
human cognitive abilities. AI labs focus on areas such as:
● Face recognition
● Speech recognition
● Solving Complex Problems
● Training Future AI Experts
● Collaboration and Networking

Libraries present in Lisp.


Lisp has a rich ecosystem of libraries and packages for various purposes. Here are some notable
libraries and areas they cover:

1. ASDF: A build system for Common Lisp, essential for managing dependencies.

2. Quicklisp: A package manager for Common Lisp, simplifying library installation and management.

3. CL-PPCRE: A regular expression library for Common Lisp.

4. Bordeaux-Threads: A library for multi-threading and parallel programming in Common Lisp.

5. Alexandria: A collection of utility functions for Common Lisp.

6. Parenscript: Transpiles Lisp-like code to JavaScript, enabling web development.

7. Hunchentoot: A web server framework for Common Lisp.

8. CLIM: The Common Lisp Interface Manager for building graphical user interfaces.

9. CLOS MOP: The Meta-Object Protocol for extending and customizing the Common Lisp Object System (CLOS).

10. LTK: A Common Lisp binding to the Tk graphical toolkit for creating cross-platform GUI applications.

11. Numpy and SciPy for Lisp (Lisp-Stat): Libraries for scientific computing and data analysis in Common Lisp.

12. LASS: A library for handling sound and audio in Common Lisp.

Nitin Kumar A20405220040


13. Clack: A web application environment that simplifies web development in Common Lisp.

14. SBCL Foreign Function Interface (FFI): Allows interfacing with C libraries from Common Lisp.

15. Inferior Shell: Provides a way to interact with external shell processes from within Common Lisp.

Nitin Kumar A20405220040


16. Clunit: A unit testing framework for Common Lisp.

These are just a few examples, and there are many more libraries and packages available to
extend the functionality of Lisp for various domains and applications. The availability of libraries
is one of the strengths of Lisp, contributing to its versatility and suitability for a wide range of
tasks.

Lisp is available on three platforms, all of them require 5-50MB disk space for installation:
● Windows
● Linux
● MacOS

Lisp IDE (Offline) –


If you're looking for an offline integrated development environment (IDE) for Lisp, there are
several options available that you can use without an internet connection. Here are a few
popular choices:

1. Emacs with SLIME:


- Emacs: Emacs is a highly extensible text editor that has excellent support for Lisp programming.
- SLIME (Superior Lisp Interaction Mode for Emacs): SLIME is a popular Emacs mode for interacting with
Common Lisp and other Lisp dialects. It provides features like code evaluation, debugging, and project management.
- Both Emacs and SLIME can be used offline, and they offer a powerful development environment for Lisp.

2. Vim with Slimv:


- Vim: Vim is another highly configurable text editor that can be set up for Lisp development.
- Slimv: Slimv is a Vim plugin that provides features similar to SLIME for Common Lisp. It allows you to work
with Lisp offline in the Vim editor.

3. CLion with Cursive (for Clojure):


- CLion: CLion is a cross-platform integrated development environment primarily designed for C and C++
development.
- Cursive: Cursive is a plugin for CLion that adds support for Clojure development. It can be used offline for Clojure
development.

4. Sublime Text with SublimeREPL:


- Sublime Text: Sublime Text is a versatile text editor known for its extensibility.
- SublimeREPL: SublimeREPL is a package for Sublime Text that can be configured to work with various Lisp
dialects. It can be used for offline Lisp development.

5. Atom with language-lisp:


- Atom: Atom is a free, open-source text editor developed by GitHub.
- language-lisp: The "language-lisp" package for Atom provides syntax highlighting and basic Lisp support. While
it may not offer all the features of a full-fledged IDE, it can be used offline for Lisp code editing.

Conclusion: Emacs with SLIME is preferred for Lisp due to its powerful features, interactive
REPL, debugging support, extensive extensions, and strong community, making it a versatile and
efficient development environment.

Lisp IDE (Online) –

Nitin Kumar A20405220040


If you prefer an online integrated development environment (IDE) for Lisp, there are a few
options available that allow you to write and run Lisp code directly in a web browser. These online
IDEs are convenient for quick experimentation and learning. Here are a couple of popular
online Lisp IDEs:

1. repl.it:
- Website: [repl.it](https://repl.it)
- Features: It provides a code editor, a REPL (Read-Eval-Print Loop) environment, and the ability to create and run
Lisp programs directly in your web browser. You can share your code and collaborate with others.

Nitin Kumar A20405220040


2. Ideone:
- Website: [Ideone](https://ideone.com)
- Features: You can write, compile, and run Lisp code in your browser. It supports various input methods and
provides a simple interface for running and testing Lisp programs.

Conclusion: Choosing repl.it for online Lisp coding is smart. It's user-friendly, supports multiple
Lisp dialects, offers collaboration, version control, and has an active community, making it ideal
for learning and development from any web-enabled device.

Online Python IDE-Jupyter Notebook

Fig 1.1: Signup/Login for Lisp

Fig 1.2: Choose the language-Lisp

Nitin Kumar A20405220040


Fig 1.3 Online IDE for Lisp

Installation of Lisp IDE- Emacs with Slime.

1. Install Emacs from their official website.


2. Install a Lisp Implementation: Before using SLIME, you need a Lisp implementation like SBCL (Steel Bank
Common Lisp) or Clozure CL.
3. Install Quicklisp (Optional): Quicklisp is a package manager for Common Lisp libraries.

Fig 1.4: Installation of Emacs

4. Install SLIME:
● Launch Emacs.
● Open the Emacs configuration file, usually named .emacs or init.el. You can find it in your home directory.
● Add the following lines to your Emacs configuration file to install and configure SLIME for your preferred
Lisp implementation (e.g., SBCL):
Nitin Kumar A20405220040
Fig 1.5: Installation of Slime

5. Using SLIME: To start using SLIME, open a Lisp source file (e.g., with a .lisp extension) or create a new
one. Then, run M-x slime (Alt + x, type "slime," and press Enter). SLIME will start, and you can use it to interact
with your chosen Lisp implementation.

Nitin Kumar A20405220040


Experiment- 11
Aim: To study the available platforms for AI programming.
There are three types of platforms available for AI programming-

D. Python
E. Lisp
F. Prolog

C. Prolog Platform:
⚫ The problems that were faced by the traditional programming languages that lead to the
evolution of prolog.
Prolog (Programming in Logic) is a declarative programming language that was developed
in the 1970s, and it evolved as a response to the limitations and challenges faced by
traditional imperative programming languages. Here are some of the problems with traditional
programming languages that led to the development and evolution of Prolog:
1. Lack of Declarative Semantics: Traditional programming languages, like C, Java, and Pascal, are imperative and
require programmers to specify how to achieve a particular task step by step. This can make code hard to read,
understand, and maintain. Prolog, on the other hand, offers a declarative approach, where you specify what you
want to achieve, and the system figures out how to do it. This makes Prolog particularly well-suited for tasks
involving complex logical relationships.

2. Inefficiency in Symbolic Reasoning: Traditional languages are not well-suited for symbolic reasoning and complex
rule-based systems. They require extensive programming to handle symbolic manipulation and rule-based
inference. Prolog, with its built-in support for symbolic reasoning, makes it easier to work with knowledge
representation and rule-based systems.
3. Limited Pattern Matching: Pattern matching is a fundamental aspect of many applications, such as text processing
and artificial intelligence. Traditional languages often lack powerful built-in pattern matching capabilities, making it
harder to work with data matching specific patterns. Prolog excels at pattern matching, making it an excellent choice
for tasks like natural language processing and expert systems.
4. Explicit Data Manipulation: Traditional languages require explicit data manipulation, which can be tedious and
error-prone. Prolog, on the other hand, uses unification and pattern matching to handle data manipulation
implicitly, simplifying the code and reducing the chance of errors.
5. Procedural Complexity: Traditional languages often lead to complex and lengthy code due to their procedural
nature. Prolog's declarative nature allows for more concise code, making it easier to express complex relationships
and logic in a compact manner.
6. Difficulties in Handling Uncertainty: Many real-world problems involve uncertainty and incomplete information.
Traditional languages struggle to handle these issues effectively. Prolog, with its ability to represent and reason with
uncertain information through probabilistic and fuzzy logic extensions, is better equipped to address such problems.

• Evolution of Prolog:
The programming language, Prolog, was born of a project aimed not at producing a
programm3ing language but at processing natural languages; in this case, French. The project
gave rise to a preliminary version of Prolog at the end of 1971 and a more definitive version at
the end of 1972.
Year Milestone

Birth of Prolog - Alain Colmerauer and Robert Kowalski laid the foundation for Prolog
1972 with the development of the first Prolog system at the University of Aix-Marseille.

Nitin Kumar A20405220040


First Interpreter - The first Prolog interpreter was implemented, which marked the
1973 practical realization of Prolog as a programming language.

Edinburgh Prolog - David H. D. Warren developed the Warren Abstract Machine (WAM)
1980 and Edinburgh Prolog, making Prolog more efficient and widely adopted.

ISO Standardization - The first official Prolog standard, Edinburgh Prolog, was proposed
1981 as an international standard, but it wasn't accepted.

1982 C-Prolog - Quintus Prolog, one of the first commercially available Prolog systems, was
developed by SRI International.

1987 ISO Prolog Standard - The International Organization for Standardization (ISO) released
the official standard for Prolog, known as ISO Prolog.

1990s Prolog Implementations - Several Prolog implementations, such as SWI-Prolog and


SICStus Prolog, were developed, enhancing the language's capabilities and
performance.

Logic Programming in AI - Prolog gained popularity in the AI and expert systems


2000s community for its natural support of symbolic reasoning and knowledge
representation.

Integration with Other Languages - Prolog saw integration with other languages and
2010s tools, enabling hybrid systems and more extensive applications.

Present Active Development - Prolog continues to be actively developed, with ongoing


improvements in performance, libraries, and compatibility.

Future Expanding Use Cases - Prolog is being explored for new applications, including natural
language processing, data analysis, and rule-based systems.

The problem domain of AI lab and the library which will be used and their distribution.

The problem domain of an AI lab encompasses the study and development of artificial intelligence
(AI) technologies and applications. It involves creating algorithms, models, and systems that mimic
human intelligence and behavior, enabling computers to perform tasks that typically require
human cognitive abilities. AI labs focus on areas such as
• Face recognition
• Speech recognition
• Solving Complex Problems
• Training Future AI Experts
• Collaboration and Networking

PROLOG IDE (Offline)


1. SWI-Prolog IDE: SWI-Prolog, one of the most widely used Prolog implementations, includes a built-in
development environment with an integrated editor, debugger, and other tools. It can be used ofline on Windows,
macOS, and Linux.
2. GNU Prolog IDE: GNU Prolog provides a simple and efficient development environment that can be used ofline
on various platforms, including Windows, macOS, and Linux.
3. Sicstus Prolog Development Environment: Sicstus Prolog, a commercial Prolog implementation, includes a
feature-rich development environment with a built-in editor, debugger, and other tools. It is available for ofline use
Nitin Kumar A20405220040
on Windows, macOS, and Linux.
4. XSB Prolog IDE: XSB Prolog offers an integrated development environment that you can use ofline. It is available
for Windows, macOS, and Linux.
5. ECLiPSe Prolog: ECLiPSe, a popular Prolog system, provides an ofline development environment that includes a
code editor, debugger, and other development tools. It is available for Windows, macOS, and Linux.

Nitin Kumar A20405220040


PROLOG IDE (Online) :-
1. SWI-Prolog Web IDE: SWI-Prolog offers an online development environment called SWISH (SWI-Prolog for
SHaring) that allows you to write and run Prolog code in your web browser. SWISH provides a web-based code
editor, a console for interacting with Prolog, and the ability to share your code with others. You can access it at
SWISH.

2. Repl.it: Repl.it is an online platform that supports various programming languages, including Prolog. It provides
an online code editor, compiler/interpreter, and collaborative coding features. You can write and run Prolog code in
your browser on Repl.it at Repl.it Prolog.

3. Ideone: Ideone is an online compiler and debugging tool that supports Prolog. You can write Prolog code in the
online editor and run it to see the output. It's available at Ideone Prolog.

4. OnlineGDB: OnlineGDB is an online IDE and debugger that supports Prolog. You can write, run, and debug
Prolog code within your web browser. It's accessible at OnlineGDB Prolog.

5. TutorialsPoint: TutorialsPoint offers an online Prolog compiler and editor that allows you to write and execute
Prolog code. You can access it at TutorialsPoint Prolog.

• Online Prolog IDE-SWISH Web IDE

Fig 1.6 Online IDE for Prolog

• Installation of SWI Offline Prolog IDE

Step 1: Visit swi-prolog.org website using any web browser.


Step 2: Click on Download which is adjacent to Home, dropdown list will appear then click on
SWI-Prolog.

Nitin Kumar A20405220040


Fig 1.7 SWI Download website

Step 3: New webpage will open, click on Stable release.


Step 4: After clicking on stable release new webpage will open which will contain stable
versions of prolog for
different platforms. Click on the one as per your system configuration. Lets take the one for 64-bit
operating system.
Step 5: After clicking on SWI-Prolog 8.4.0-1 for Microsoft Windows (64 bit), a new webpage
will open, check on I understand checkbox to make the download link active.
Step 6: Now check for the executable file in downloads in your system and run it.
Step 7: It will prompt confirmation to make changes to your system. Click on Yes.

Fig 1.8 User Account Control prompt

Step 8: Setup screen will appear, click on Next.

Step 9: The next screen will be of License Agreement, click on I Agree.


Step 10: After it there will be screen of installing options so check the box for Add swipl to the
system path for all users, and also check the box for create a desktop icon and then click on the
Next button.

Nitin Kumar A20405220040


Fig 1.9 Installation formatting

Step 11:The last screen is of choosing components, all components are already marked so don’t
change anything just click on Install button.
Step 12: After this installation process will start and will hardly take a minute to complete the
installation.
Step 13: Click on Finish after the installation process is complete.
Step 14: SWI Prolog is successfully installed on the system and an icon is created on the desktop.
Step 15: Run the software and see the interface.

Fig 2.0 SWI Offline Prolog IDE Interface

Nitin Kumar A20405220040


Experiment-12

Aim: To implement the two point path robot.


The robotic path planning problem is a classic. A robot, with certain dimensions, is attempting to navigate
between point A and point B while avoiding the set of all obstacles, Cobs.A two-point path robot, also
known as a two-point motion robot, is a type of robot that can move between two specific points in a
given environment. This type of robot is typically used in applications where precise movement between
two fixed locations is required.These robots are commonly used in scenarios where tasks involve moving
objects or tools between two fixed positions, such as pick-and-place operations in manufacturing or
assembly lines. They are often simpler in design and control compared to robots with more sophisticated
mobility and functionality.

Fig 12.1

Algorithm:
Step-1 Define a grid representing the environment with obstacles. 0 represents a passable cell, and 1
represents an obstacle and define directions (up, down, left, right) for movement.
Step-2 Create two separate queues for the start and end searches, respectively and create two sets for
tracking visited nodes in the start and end searches.
Step-3 Now add the start node to and the end node .While both queue_start and queue_end have nodes.Pop
a node from both queue_start and queue_end If current_start is equal to current_end, or current_start is in
visited_end .
Return True
Step-4 For each direction in directions, check neighboring nodes Ensure the neighboring node is within the
grid boundaries.Ensure the neighboring node is not an obstacle.
Step-5 If conditions are met, add the neighboring node to the appropriate queue .
Nitin Kumar A20405220040
Step-6 If the loop completes without finding a meeting point, return False .

Nitin Kumar A20405220040


Code:

Output:

Nitin Kumar A20405220040


Nitin Kumar A20405220040

You might also like