Lab 4 Uninformed Search
Lab 4 Uninformed Search
In Lab-03, we introduced methods and representations that are used for solving problems using Artificial
Intelligence techniques such as search. In this Lab, we will implement an Uninformed Search Algorithm to
search for solving a particular problems.
Figure 0-1. Nodes are the data structures from which the search tree is constructed. Each has a parent, a state, and various
bookkeeping fields. Arrows point from child to parent.
For each node n of the tree, we have a structure that contains four components:
• n.STATE: the state in the state space to which the node corresponds;
• n.PARENT: the node in the search tree that generated this node;
• n.ACTION: the action that was applied to the parent to generate the node;
• n.PATH-COST: the cost, traditionally denoted by g(n), of the path from the initial state to the
node, as indicated by the parent pointers.
S########
#.#....#.
#.#.##.#.
#...#....
###.#####
#.......#
######.##
#......#E
#########
In this matrix, the "S" represents the starting point, the "E" represents the endpoint, and the "#"
characters represent walls or barriers that cannot be passed through. The "." characters represent open
passages that can be traversed. The objective is to navigate from the starting point to the endpoint by
moving through the open passages, while avoiding the walls and dead ends.
1.5 Lab Tasks
Task 1.
Using Breadth First Search (BFS) algorithm, write out the order in which nodes are added to the explored
set, with start state S and goal state G. Break ties in alphabetical order. Additionally, what is the path
returned by each algorithm? What is the total cost of each path?
Task 2.
The missionaries and cannibals problem is usually stated as follows. Three missionaries and three
cannibals are on one side of a river, along with a boat that can hold one or two people. Find a way to get
everyone to the other side without ever leaving a group of missionaries in one place outnumbered by the
cannibals in that place. Implement and solve the problem optimally using following search algorithm. Is it
a good idea to check for repeated states?
a. BFS
b. DFS
Task 3.
In Figure 1 you will find a matrix (list of lists) that represents a simple labyrinth. 0 represents a wall and 1
represents a passage. 2 represents a door that requires a key to be opened and 3 represents a supply of
keys.
a. Write a function that takes a labyrinth matrix like the one shown above as argument and draws it
using the characters ## for walls, two spaces for empty passages, D for doors and K for keys. This
function should also accept a list of (x,y) tuples that represent positions visited by a robot in
the labyrinth, you should print the character . at these points (note that you should print either a
whitespace, D or K in addition to the dot).
b. Write a function that takes a labyrinth matrix like the one above and the x and y coordinates for
a place in the labyrinth as arguments, and returns a list of the coordinates (tuples of x and y) of
all adjacent places (vertically and horizontally) that are passages (i.e. have value 1). Note that the
function must handle all input coordinates in a consistent way, and not access memory outside
the size of the labyrinth array under any circumstance.