Sei sulla pagina 1di 7

Enr No: 150280723018

ASSIGNMENT: 1
AIM :
Implement the depth-first search (DFS) algorithm in the depthFirstSearchfunction in search.py.
To make your algorithm complete, write the graph search version of DFS, which avoids
expanding any already visited states.
Your code should quickly find a solution for:
python pacman.py -l tinyMaze -p SearchAgent
python pacman.py -l mediumMaze -p SearchAgent
python pacman.py -l bigMaze -z .5 -p SearchAgent
The Pacman board will show an overlay of the states explored, and the order in which they were
explored (brighter red means earlier exploration). Is the exploration order what you would have
expected? Does Pacman actually go to all the explored squares on his way to the goal?
Solution :
A. Framework
We used the University of California Berkeleys Pac-Man framework implemented in Python to
test our approach. The Pac-Man projects were developed for UC Berkeleys introductory
artificial intelligence course. They allow an array of AI techniques to be tested using a common
framework. However, these projects do not focus on building AI for video games. Instead, this
platform serves as an excellent test-bed for graph search algorithms. The Pac-Man framework
has mazes of three different sizes. The small maze is a 20 by 8 grid, the medium maze is a 34 by
16 grid and the big maze is a 35 by 35 grid. In the problem where Pac-man has to find just one
dot, Pac-man and the dot are usually placed on opposite corners. Other variations have a
combinations of dots and open spaces to elicit specific movements through the maze dependent
on the search techniques. It must be noted that our work involves only non-adversarial search, so
the grids we use do not have ghosts to actively avoid.

Enr No: 150280723018

B. Singgle Target Search


We started off by implementing deterministic graph search techniques on the Pac-Man
framework. The methods we wrote were depth-first search, so the main chunk of our work was
developing a heuristic that improves on the current state of the art with respect to approximation
and compute cycles required. This is accomplished mainly by minimizing the number of nodes
examined during the search. Our implementation minimizes the time taken to generate the path
cost from the start to the current node by using dynamic programming with memorization to
keep a table of previously computed paths to visited nodes.

C. Evaluation
The final score of the game is used as a comparison metric for how close of an approximation
our heuristic is to the true solution, determined by the breadth-first search in our tests.
The final score is a combination of the total time taken for the method to reach completion and
the number of dots on the grid (assuming each agent acquired every dot).
Type of Search

Small
S

NE

Maze Size
Medium
S
NE

Big
S

NE

depth-first search
Table: Score(S) And Number Of Nodes Expanded (Ne) For Each Search Strategy In Small,
Medium, And Lage Mazes

Enr No: 150280723018

def depthFirstSearch(problem):
fringe = util.Stack()
fringe.push( (problem.getStartState(), [], []) )
while not fringe.isEmpty():
node, actions, visited = fringe.pop()
for coord, direction, steps in problem.getSuccessors(node):
if not coord in visited:
if problem.isGoalState(coord):
return actions + [direction]
fringe.push((coord, actions + [direction], visited + [node] ))

Enr No: 150280723018

ASSIGNMENT:2
AIM: Write a PROLOG program to implement Tower Of Hanoi Problem.
Toh.pl
move(1,X,Y,_):-

write('Move top disk from '),


write(X ),
write(' to '),
write(Y),
nl.
move(N,X,Y,Z):- N>1,
M is N-1,
move(M,X,Z,Y),
move(1,X,Y,_),
move(M,Z,Y,X).
?-move(4,left,right,center).
Move
Move
Move
Move
Move
Move
Move
Move
Move
Move
Move
Move
Move
Move
Move
true

top
top
top
top
top
top
top
top
top
top
top
top
top
top
top

disk
disk
disk
disk
disk
disk
disk
disk
disk
disk
disk
disk
disk
disk
disk

from
from
from
from
from
from
from
from
from
from
from
from
from
from
from

left to center
left to right
center to right
left to center
right to left
right to center
left to center
left to right
center to right
center to left
right to left
center to right
left to center
left to right
center to right

Enr No: 150280723018

ASSIGNMENT:3
AIM: Write a PROLOG program N-QUEEN problem.
Queen.pl
solve(P):- perm([1,2,3,4,5,6,7,8],P),
combine([1,2,3,4,5,6,7,8],P,S,D),
all_diff(S),
all_diff(D).
combine([X1|X],[Y1|Y],[S1|S],[D1|D]):- S1 is X1+Y1,
D1 is X1-Y1,
combine(X,Y,S,D).
combine([],[],[],[]).
all_diff([X|Y]):-\+member(X|Y),all_diff(Y).
all_diff([X]).
?-solve(P).
P=[5,2,6,1,7,4,8,3];
P=[6,3,5,7,1,4,2,8];

Enr No: 150280723018

ASSIGNMENT:4
AIM: Write a PROLOG program Map coloring Problem
Map_color.pl
adjacent(1,2).
adjacent(2,1).
adjacent(1,3).
adjacent(3,1).
adjacent(1,4).
adjacent(4,1).
adjacent(1,5).
adjacent(5,1).
adjacent(2,3).
adjacent(3,2).
adjacent(2,4).
adjacent(4,2).
adjacent(3,4).
adjacent(4,3).
adjacent(4,5).
adjacent(5,4).
color(1,red,a).
color(2,blue,a).
color(3,green,a).
color(4,yellow,a).
color(5,blue,a).
color(1,red,b).
color(2,blue,b).
color(3,green,b).
color(4,blue,b).
color(5,green,b).
conflict(Coloring):adjacent(X,Y),color(X,Color,Coloring),color(Y,Color,Coloring).
conflict(R1,R2,Coloring):adjacent(R1,R2),color(R1,Color,Coloring),color(R2,Color,Coloring).
?- conflict(Which).
Which = b .
?- conflict(R1,R2,b).
R1 = 2,
R2 = 4 .
conflict(R1,R2,b),color(R1,C,b).
R1 = 2,
R2 = 4,
C = blue

Enr No: 150280723018

ASSIGNMENT:5
AIM: Write a PROLOG program Factorial Problem.
Fact.pl
factorial(0,1).
factorial(N,F):- N>0,
N1 is N-1,
factorial(N1,F1),
F is N*F1.
?- factorial(5,F).
F = 120

Potrebbero piacerti anche