Professional Documents
Culture Documents
INDEX
Sr. Title Pg. Start Complete Sign Marks
No. No. Date Date
1 Write a program to implement Tic-Tac- 1
Toe game problem
2 Write a program to implement BFS (for 8 9
puzzle problem or Water Jug problem or
any AI search
problem)
3 Write a program to implement DFS (for 8 13
puzzle problem or Water Jug problem or
any AI search
problem)
4 Write a program to implement Single 17
Player Game (Using Heuristic Function)
5 Write a program to Implement A* 19
Algorithm
6 6.1 Enter the facts for the following 21
predicates for a Turbo Prolog
program
likes (person, drink)
enjoy (person, hobby)
plays (person, instrument)
6.2 Write a Prolog program for your 22
Family Tree
6.3 Develop a medical diagnostic expert 27
system using Prolog
7 7.1 Find out sum of numbers from 1 to 28
10
7.2 Print the following pattern: 29
*,**,***,****
7.3 Find out factorial of any given 30
number
8 8.1 Write a program to check whether a 31
year is leap year or not
8.2 Write a turbo Prolog program to 32
display integer numbers from 1 to
100 on
successive lines. However when a
number is divisible by 3 or 7,
display “Buzz 3”or Buzz 7”
respectively next to the number. If
the number is the number. The
output should therefore be as follows
9 Write a prolog program to generate 34
Fibonacci Series
10 Write the Conceptual Dependency for 35
following statements.
(a) John gives Mary a book
(b) John gave Mary the book yesterday
AIRTIFICIAL INTELLIGENCE(2180703) ENROLL: 140513107003
Practical 1
#include<stdio.h>
#include<conio.h>
void Board();
void PlayerX();
void PlayerO();
void Player_win();
void check();
int win=0,wrong_X=0,wrong_O=0,chk=0;
char name_X[30];
char name_O[30];
int pos_for_X[3][3];
int pos_for_O[3][3];
int pos_marked[3][3];
void main()
{
int i,ch,j;
char ans;
/* clrscr();
printf("\n\t\t\t\tTIC TAC TOE");
printf("\n\t\t\t\t");
for(i=1;i<=11;i++)
{
delay(10);
printf("*");
}*/
do
{
clrscr();
printf("\n\t\t\t\tTIC TAC TOE");
printf("\n\t\t\t\t");
for(i=1;i<=11;i++)
{
delay(10);
printf("*");
}
printf("\n1.Start The Game");
printf("\n2.Quit The Game");
printf("\nEnter your choice(1-2) : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
chk=0;
win=0;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
}
Board();
if(win!=1)
{
printf("\n\t\t\tMATCH DRAWS!!");
printf("\nPress any key.......");
}
getch();
break;
case 2:
printf("\n\n\n\t\t\tThank You For Playing The Game.");
printf("\n\t\t\t###############################");
getch();
exit(1);
break;
}
printf("\nWant To Play(Y/N) ? ");
fflush(stdin);
scanf("%c",&ans);
}while(ans=='y' || ans=='Y');
}
void Board()
{
int i,j;
clrscr();
printf("\n\t\t\t\tTIC TAC TOE BOARD");
printf("\n\t\t\t\t*****************");
printf("\n\n\n");
printf("\n\t\t\t 1\t 2\t 3");
for(i=1;i<=3;i++)
{
printf("\n \t\t\t _____________________________");
printf("\n \t\t\t?\t ?\t ?\t ?");
printf("\n\t\t%d\t",i);
for(j=1;j<=3;j++)
{
if(pos_for_X[i][j]==1)
{
printf(" X");
printf(" ");
}
for(i=1;i<=3;i++)
{
if(pos_for_O[i][1]==1 && pos_for_O[i][2]==1 && pos_for_O[i]
[3]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_O);
printf("\nPress any key.....");
return;
}
}
for(i=1;i<=3;i++)
{
if(pos_for_O[1][i]==1 && pos_for_O[2][i]==1 && pos_for_O[3]
[i]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_O);
printf("\nPress any key.....");
return;
}
}
if(pos_for_O[1][1]==1 && pos_for_O[2][2]==1 && pos_for_O[3][3]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_O);
printf("\nPress any key.....");
return;
}
else if(pos_for_O[1][3]==1 && pos_for_O[2][2]==1 &&
pos_for_O[3][1]==1)
{
win=1;
printf("\n\nRESULT: %s wins!!",name_O);
printf("\nPress any key.....");
return;
}
}
void check()
{
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
if(pos_marked[i][j]==1)
chk++;
else
continue;
}}}
struct node
{
int x, y;
struct node *next;
void main()
{
int maxJug1, maxJug2, reqJug1, reqJug2;
clrscr();
printf("Enter the maximum capacity of jug1 :: ");
scanf("%d",&maxJug1);
printf("Enter the maximum capacity of jug2 :: ");
scanf("%d",&maxJug2);
printf("Enter the required water in jug1 :: ");
scanf("%d",&reqJug1);
printf("Enter the required water in jug2 :: ");
scanf("%d",&reqJug2);
generateTree(maxJug1, maxJug2, reqJug1, reqJug2);
BFS(reqJug1, reqJug2);
getch();
}
OUTPUT
Practical 3
#include<stdio.h>
#include<conio.h>
struct node
{
int x, y;
struct node *next;
void main()
{
int maxJug1, maxJug2, reqJug1, reqJug2;
clrscr();
printf("Enter the maximum capacity of jug1 :: ");
scanf("%d",&maxJug1);
printf("Enter the maximum capacity of jug2 :: ");
scanf("%d",&maxJug2);
printf("Enter the required water in jug1 :: ");
scanf("%d",&reqJug1);
printf("Enter the required water in jug2 :: ");
scanf("%d",&reqJug2);
generateTree(maxJug1, maxJug2, reqJug1, reqJug2);
DFS(reqJug1, reqJug2);
getch();
}
OUTPUT
Practical 4
#include <stdio.h>
#include<conio.h>
int main()
int num;
clrscr();
scanf("%d", &num);
if (num == 1)
return;
printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg);
OUTPUT
Practical 5
#include <stdio.h>
#include<conio.h>
int main()
{
int c, first, last, middle, n, search, array[100];
clrscr();
printf("Enter number of elements\n");
scanf("%d",&n);
first = 0;
last = n - 1;
middle = (first+last)/2;
OUTPUT
clauses
likes(megha,wine).
likes(ashish,wine).
likes(chaitali,coke).
likes(maya,coke).
likes(ravi,wine).
hobby(megha,cricket).
hobby(ravi,chess).
hobby(chaitali,chess).
hobby(maya,cricket).
hobby(ravi,cricket).
plays(megha,piano).
plays(maya,violin).
plays(maya,piano).
plays(ravi,piano).
OUTPUT
Practical 6.2
predicates
parent(symbol, symbol)
male(symbol)
female(symbol)
mother(symbol, symbol)
son(symbol, symbol)
daughter(symbol, symbol)
grandfather(symbol, symbol)
grandmother(symbol, symbol)
brother(symbol, symbol)
sister(symbol, symbol)
uncle(symbol, symbol)
aunt(symbol, symbol)
nephew(symbol, symbol)
niece(symbol, symbol)
cousines(symbol, symbol)
clauses
male(jonathan).
male(john).
male(kelly).
male(arnold).
male(louise).
female(jenifer).
female(marry).
female(alies).
female(martha).
female(nency).
mother(M,C):-
clearwindow(),
female(M),
parent(M,C),
write(M," is a Mother of ",C),nl.
son(S,P):-
clearwindow(),
male(S),
parent(P,S),
write(S," is a son of ",P),nl.
daughter(D,P):-
clearwindow(),
female(D),
parent(P,D),
write(D," is a daughter of ",P),nl.
grandfather(GF,C):-
clearwindow(),
grandmother(GM,C):-
clearwindow(),
female(GM),
parent(GM,M),
parent(M,C),
write(GM," is a GrandMother of ",C),nl.
brother(B,S):-
male(B),
parent(P,B),
parent(P,S),
write(B," is a brother of ",S),nl.
sister(S,B):-
female(S),
parent(P,S),
parent(P,B),
write(S," is a sister of ",B),nl.
uncle(U,C):-
clearwindow(),
brother(U,P),
parent(P,C),
write(U," is a uncle of ",C),nl.
aunt(A,C):-
clearwindow(),
sister(A,P),
nephew(C,P):-
clearwindow(),
male(C),
brother(P,A),
parent(A,C),
write(C," is a nephew of ",P),nl.
nephew(C,P):-
clearwindow(),
male(C),
sister(P,A),
parent(A,C),
write(C," is a nephew of ",P),nl.
niece(C,P):-
clearwindow(),
female(C),
brother(P,A),
parent(A,C),
write(C," is a niece of ",P),nl.
niece(C,P):-
clearwindow(),
female(C),
sister(P,A),
parent(A,C),
write(C," is a niece of ",P),nl.
cousines(C1,C2):-
clearwindow(),
cousines(C1,C2):-
clearwindow(),
parent(A,C1),
parent(B,C2),
sister(A,B),
write(C1," is a cousine of ",C2),nl.
OUTPUT
Practical 6.3
domains
disease, indication=symbol
predicates
symptom (disease, indication)
clauses
symptom(chicken_pox,high_fever).
symptom(chicken_pox,chills).
symptom(flu,chills).
symptom(cold,runny_nose).
symptom(flu,runny_nose).
OUTPUT
list=integer*
predicates
findsum(list)
sum(list,integer)
clauses
findsum(L):-
sum(L,Sum),
write("\nSum Of Given List : ",Sum).
sum([],0).
sum([X|Tail],Sum):-
sum(Tail,Temp),
Sum=Temp+X.
OUTPUT
OUTPUT
predicates
go
fact(integer, integer)
clauses
go:-
fact(N,A),
write (A).
fact(1,A):-
A=1.
fact(N,A):-
B=N-1,
Fact(B,S),
A= N*S.
OUTPUT
Practical 8
predicates go
check(integer)
clauses
go:-
write("Enter the Year : "),
readint(Year),
check(Year).
check(Y):-
Z=0,
A=Y mod 1000,
B=A mod 100,
Z=B mod 4,
write("Year ",Y," is a Leap Year.").
check(Y):-
write("Year ",Y," is not a leap year.").
OUTPUT
predicates
go
buzz(integer)
check(integer)
buzz3(integer)
buzz7(integer)
clauses
go:-
buzz(1).
buzz(26).
buzz(N):-
write(N),
check(N),
NN=N+1,
buzz(NN).
check(N):-
R=N mod 3,
buzz3(R),
P=N mod 7,
buzz7(P),
write("\n").
buzz3(0):-
write(" Buzz3").
buzz3(X).
buzz7(0):-
write(" Buzz7").
buzz7(X).