You are on page 1of 29

Artificial Intelligence (2180703) 150330107077

Practical: 1

Aim: Write a program to implement Tic-Tac-Toe Game problem.


#include <stdio.h>
#include <conio.h>
char square[10] = {'o','1','2','3','4','5','6','7','8','9'};
int checkwin();
void board();
int main()
{
int player = 1,i,choice;
char mark;
clrscr();
do
{
board();
player=(player%2)?1:2;
printf( "Player %d",player);
printf(" enter a number: ");
scanf("%d",&choice);
mark=(player == 1) ? 'X' : 'O';
if (choice == 1 &&square[1] == '1')
square[1] = mark;
else if (choice == 2 &&square[2] == '2')
square[2] = mark;
else if (choice == 3 &&square[3] == '3')
square[3] = mark;
else if (choice == 4 &&square[4] == '4')
square[4] = mark;
else if (choice == 5 &&square[5] == '5')
square[5] = mark;
else if (choice == 6 &&square[6] == '6')
square[6] = mark;
else if (choice == 7 &&square[7] == '7')
square[7] = mark;
else if (choice == 8 &&square[8] == '8')
square[8] = mark;
else if (choice == 9 &&square[9] == '9')
square[9] = mark;
else
{
printf("\nInvalid move ");
player--;
getch();
}
i=checkwin();
player++;

}while(i==-1);
MGITER/CE/2018-19 Page 1
Artificial Intelligence (2180703) 150330107077

board();
if(i==1)
{
printf("\nPlayer %d ",--player);
printf(" win ");
}
else
printf("\nGame draw");
getch();
return 0;
}
int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])
return 1;
else if (square[4] == square[5] && square[5] == square[6])
return 1;
else if (square[7] == square[8] && square[8] == square[9])
return 1;
else if (square[1] == square[4] && square[4] == square[7])
return 1;
else if (square[2] == square[5] && square[5] == square[8])
return 1;
else if (square[3] == square[6] && square[6] == square[9])
return 1;
else if (square[1] == square[5] && square[5] == square[9])
return 1;
else if (square[3] == square[5] && square[5] == square[7])
return 1;
else if (square[1] != '1' && square[2] != '2' && square[3] != '3' &&
square[4] != '4' && square[5] != '5' && square[6] != '6' && square[7] != '7' &&
square[8] != '8' && square[9] != '9')
return 0;
else
return -1;
}
/*******************************************************************
FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
********************************************************************/
void board()
{
clrscr();
printf(" \n\n\tTic Tac Toe\n\n");
printf("Player 1 (X) - Player 2 (O)\n\n");
printf("\n");
printf(" | | \n");
printf(" %c" ,square[1]);
printf(" | %c",square[2]);
printf(" | %c",square[3]);
printf("\n");

MGITER/CE/2018-19 Page 2
Artificial Intelligence (2180703) 150330107077

printf("_____|_____|_____\n");
printf(" | | \n");
printf(" %c" ,square[4]);
printf(" | %c",square[5]);
printf(" | %c",square[6]);
printf("\n");
printf("_____|_____|_____\n");
printf(" | | \n");
printf(" %c" ,square[7]);
printf(" | %c",square[8]);
printf(" | %c",square[9]);
printf("\n");
}

Output:

MGITER/CE/2018-19 Page 3
Artificial Intelligence (2180703) 150330107077

Practical: 2

Aim: Write a Prolog Program to Demonstrate Family Relationship.


PROLOG PROGRAM:

male(jack).
male(james).
male(jacob).
male(justin).
male(edward).
female(shanshan).
female(weiwei).
female(erxia).
female(xiaolin).
parent(jack,shanshan,james).
parent(jack,shanshan,jacob).
parent(james,weiwei,edward).
parent(jacob,erxia,justin).
parent(jacob,erxia,xiaolin).
brother(james,jacob).
brother(jacob,james).
brother(edward,justin).
brother(justin,edward).
sister(xiaolin,justin).
sister(xiaolin,edward).

father(X,Y) :- parent(X,Z,Y).
mother(X,Y) :- parent(Z,X,Y).

son(X,Y,Z) :- male(X),father(Y,X),mother(Z,X).
daughter(X,Y,Z) :- female(X),father(Y,X),mother(Z,X).

wife(X,Y) :- female(X),parent(Y,X,Z).
grandfather(X,Y) :- male(X),father(X,Z),father(Z,Y).

uncle(X,Y) :- male(X),brother(X,Z),father(Z,Y).
aunt(X,Y) :- wife(X,Z),uncle(Z,Y).

cousin(X,Y) :- father(Z,X),brother(Z,W),father(W,Y).

ancestor(X,Y,Z) :- parent(X,Y,Z).
ancestor(X,Y,Z) :- parent(X,Y,W),ancestor(W,U,Z).

MGITER/CE/2018-19 Page 4
Artificial Intelligence (2180703) 150330107077

Output:

MGITER/CE/2018-19 Page 5
Artificial Intelligence (2180703) 150330107077

MGITER/CE/2018-19 Page 6
Artificial Intelligence (2180703) 150330107077

Practical: 3

Aim: Write a PROLOG program to find the addition of two numbers.


PROLOG PROGRAM:
sum(X,Y):-S is X+Y,write(S).

Output:

MGITER/CE/2018-19 Page 7
Artificial Intelligence (2180703) 150330107077

Practical: 4

Aim: Give an opportunity to user to re-enter the password ‘n’ no. Of Times, on
entering wrong password.
PROLOG PROGRAM:

db(ben,10).

go(X,Y):-write('Enter Username='),read(X), write('Enter Password='),read(Y).

login:-go(X,Y),db(X,Y),nl, write('your username '),write(X),write(' & password is '),write(Y).

login:-write('....Incorrect Password try again....'),nl,login.

Output:

MGITER/CE/2018-19 Page 8
Artificial Intelligence (2180703) 150330107077

Practical: 5

Aim: Write a program to create Database for Hobbies of Different Person.

PROLOG PROGRAM:

hobby(tony,coding).

hobby(ninja,gaming).

hobby(quill,dancing).

hobby(howard,reading).

Output:

MGITER/CE/2018-19 Page 9
Artificial Intelligence (2180703) 150330107077

Practical: 6

Aim:Write a PROLOG program for diagnosis the childhood diseases.

PROLOG PROGRAM:

symtom(ben,fever).

symtom(ben,cold).

symtom(ben,stomachache).

symtom(ben,running_nose).

symtom(ben,body_ache).

dis(X,malaria):-symtom(X,fever),symtom(X,headache),symtom(X,running_nose).

dis2(X,jaundice):-symtom(X,fever),symtom(X,stomachache),symtom(X,body_ache).

Output:

MGITER/CE/2018-19 Page 10
Artificial Intelligence (2180703) 150330107077

Practical: 7

Aim: Write a PROLOG program To check if a given year is a Leap Year or not.
PROLOG PROGRAM:

go:- write('Enter the year'),nl,read(X),ckeck(X).

ckeck(X):- (N is (X mod 4),N > 0,write('year is not leap year');


N is 0,write('year is leap year')).

Output:

MGITER/CE/2018-19 Page 11
Artificial Intelligence (2180703) 150330107077

Practical: 8

Aim :Write a PROLOG program to find the factorial of a given number:

PROLOG PROGRAM:

fact(0, 1).
fact(N, F):-N > 0, N1 is N-1, fact(N1, F1), F is N*F1.

Output:

MGITER/CE/2018-19 Page 12
Artificial Intelligence (2180703) 150330107077

Practical: 9

Aim: Write a PROLOG program to find Fibonacci series.

PROLOG PROGRAM:

go:-write('Enter no='),read(N),fibo(1,1,0,N).

fibo(_,_,_,0).

fibo(A,B,C,N):- N > 0, X is B, Y is C, Z is X + Y, write(Z), write(""), D is N - 1,fibo(X,Y,Z,D).

Output:

MGITER/CE/2018-19 Page 13
Artificial Intelligence (2180703) 150330107077

Practical: 10

Aim: Write a PROLOG program based on list.

1) To find the length of a list.


PROLOG PROGRAM:

len_ls([],0).
len_ls([H|T],L):-len_ls(T,LL),L is LL+1.

Output:

2) To find whether given element is a member of a list.


PROLOG PROGRAM:

m1(E,[E|T]).

m1(E,[_|T]):-m1(E,T).

Output:

MGITER/CE/2018-19 Page 14
Artificial Intelligence (2180703) 150330107077

Practical: 11

Aim: Write a PROLOG program to solve WATER-JUG problem.


PROLOG PROGRAM:

jug(integer, integer).
jug(2, _).
jug(0, 2):-
write('(0, 2)'), nl,
write('(2, 0)'), nl.
jug(4, 0):-
write('(4, 0)'), nl,
jug(0, 0).
jug(4, 3):-
write('(4, 3)'), nl,
jug(0, 0).
jug(3, 0):-
write('(3, 0)'), nl,
jug(3, 3).
jug(X, 0):-
write('('),write(X),write(', 0)'), nl,
jug(0, 3).
jug(0, 3):-
write('(0, 3)'), nl,
jug(3, 0).
jug(0, X):-
write('(0,'),write(X),write(' )'), nl,
jug(0, 0).
jug(3, 3):-
write('(3, 3)'), nl,
jug(4, 2).
jug(4, 2):-
write('(4, 2)'), nl,
write('(2, 0)'), nl,
jug(2, 0).
jug(X, Y):-
X>4,
fail,
Y>3,
fail.

MGITER/CE/2018-19 Page 15
Artificial Intelligence (2180703) 150330107077

Output:

MGITER/CE/2018-19 Page 16
Artificial Intelligence (2180703) 150330107077

Practical: 12

Aim: Write a PROLOG program for TRAVELING SALESMAN problem.

PROLOG PROGRAM:

road(newyork,boston,60).
road(newyork,philadelphia,40).
road(philadelphia,boston,180).
dist(X,Y):-road(X,Z,D),road(Z,Y,S),F is D + S,write('Distance='),write(F).
goal:-write('Enter source='),read(X),nl,write('Enter destination='),read(Y),nl,dist(X,Y,D).
dist(X,Y,D):-road(X,Y,D),nl,write('Distance between '),write(X),write(' & '),write(Y),nl,
write('Distance='),write(D).
dist(X,Y,D):-road(X,Z,D),road(Z,W,F),road(W,Y,G),N is D + F + G,nl,
write('Distance between '),write(X),write(' & '),write(Y),nl,
write('Distance='),write(N).

Output:

MGITER/CE/2018-19 Page 17
Artificial Intelligence (2180703) 150330107077

Practical: 13

Aim: Write a PROLOG program based on list.

1. To reverse the list.

reverse([],[]).

reverse([H|T],R):-reverse(T,RT),append(RT,[H],R).

Output:

2. To add the member of a given list.


sum([],0).

sum([H|T],S):-sum(T,Temp),S is Temp+H.

Output:

MGITER/CE/2018-19 Page 18
Artificial Intelligence (2180703) 150330107077

Practical: 14

Aim: Write a PROLOG program to find the Greatest Common Divisor.


gcd(M,0,M).
gcd(M,N,Result):-N>0,Rem is M mod N,gcd(N,Rem,Result).

Output:

MGITER/CE/2018-19 Page 19
Artificial Intelligence (2180703) 150330107077

Practical: 15

Aim: Write aprogram to find simple interest.


go:-write('Enter principal :'),read(P), write('Enter rate: '),read(R),write('Enter year: '),read(N),
I is P*R*N, S is I/100,
write('Simple Intres is='),write(S).

Output:

MGITER/CE/2018-19 Page 20
Artificial Intelligence (2180703) 150330107077

Practical: 16

Aim: Convert the following Prolog Predicates into Semantic Net


cat(tom).
cat(cat1).
mat(mat1).
sat_on(cat1,mat1).
bird(bird1).
caught(tom,bird1).
like(X,cream) :– cat(X).
mammal(X) :– cat(X).
has(X,fur) :– mammal(X).
animal(X) :– mammal(X).
animal(X) :– bird(X).
owns(john,tom).
is_coloured(tom,ginger).

Answer:

is intended to represent the


data:
Tom is a cat.
Tom caught a bird.
Tom is owned by John.
Tom is ginger in colour.
Cats like cream.
The cat sat on the mat.
A cat is a mammal.
A bird is an animal.
All mammals are animals.
Mammals have fur.

MGITER/CE/2018-19 Page 21
Artificial Intelligence (2180703) 150330107077

Practical: 17

Aim: Write the Conceptual Dependency tor following Statements

(a) John gives Mary a book


(b) John gave Mary the book yesterday

Answer:
(a)

(b)

MGITER/CE/2018-19 Page 22
Artificial Intelligence (2180703) 150330107077

OPEN ENDED PROBLEM

1) Describe the major sub fields and paradigms of AI?

The major sub fields of AI include:

 Machine Learning:
Machine learning is the incredibly powerful application of a simple concept: Look at the
inputs, try some outputs, see what happens. Of course, the mechanics behind this application
are the life's work of many amazing researcher, so this simple formulation belies how
complicated the whole thing can be.
However, machine learning itself mostly revolves around training a machine learning
algorithm around a best-guess utility function until it can consistently produce outputs that
increase the resulting value of this utility function given a set of inputs. You'll note that this
sounds quite similar to the interpretation of "intelligence" I give in the description of AGI
above.
 Natural Language Processing:
This is a specific field in which one attempts to create programs that will, given an input
formulated in a "natural" human language (usually in the form of a text string), attempt to use
various common techniques in order to construct a model as accurate as possible of what was
said and what those words correspond to.
Frequently, this is to connect this model into various subprograms that will give various
outputs, with purpose ranging from finding a hotel when asked to activating a timer program
with parameters taken from the derived model. There are various disciplines involved in this
type of work that aren't strictly "AI" related, but in common usage the term AI refers to this
type of program frequently enough to be worth mentioning.
 Super Intelligence:
So far, most research on this type of intelligence is theoretical and attempts to predict the
conditions by which such an intelligence could arise and/or the properties such a being would
have. Some people would put this and AGI under the same label, with the assertion that one
naturally follows from the other, but this is not yet certain.
 Hard coded Decisional Algorithms:
These are almost always unique, and involve looking at a set of inputs, following an
algorithm, and deriving an appropriate output, based on the internal model that the

MGITER/CE/2018-19 Page 23
Artificial Intelligence (2180703) 150330107077

programmer put into this program. In short, they're just programs (or subprograms), with
their algorithm tailored for a specific purpose that involves making decisions that appear
"intelligent" to an untrained observer, earning themselves the "AI programs" label early on in
computing history.
 Video game AI:
Subprograms in a video game that control the behaviour of certain elements of said game.
They usually involve some graph algorithms (see below), especially for path finding, and
some tailored decisional algorithms created by the game developers specifically for a
particular game.

AI Paradigms:

 AI and its dimensions


We are living in a period of rapid change, where AI will transform every aspect of our lives
and the fabric of our society. It will affect most human activities from supply chains to health
care to education, manufacturing, entertainment and even space exploration.
It is key to understand the dimensions of what AI really means. This “new” technology has
been around for 6 decades, starting with rule-based systems and currently evolving to
machine learning and deep reinforced learning (machines training machines).
These technologies are able to enhance human capabilities, including natural language
systems, and the myriad of applications that have taken over our devices and are getting
substantially better every year as data becomes more abundant and freely or easily accessible
for early-stage companies and innovators.
 The Future of AI
It is expected that many such AI technologies will start to be applied across sectors,
commercialised, and later upgraded. A process fuelled by the exponential increase of
investment across AI, culminating with 2017, when over $11bn was invested across 1174
deals, doubling from 2016 in absolute and relative terms.
This sector is perhaps the hottest in terms of exits and acquisitions, with over 133 such deals
in 2017 and over
$18bn invested. It seems that both corporate and other sector players are starting to
consolidate across verticals.

MGITER/CE/2018-19 Page 24
Artificial Intelligence (2180703) 150330107077

We are witnessing in real time the changes that could potentially rethink every industry and
area of human activity.Among some the technologies expected to emerge, enter the market
and peak, over the next three decades are:
Artificial General Intelligence
Cognitive Computing
Conversational user interface
Autonomous vehicles
Virtual Reality
Robotics and Smart Dusts

2) What are the major challenges in the field of AI?

When we say that technology is driving and shaping the future of tomorrow, we do mean that
technology has its definite effects on our lifestyle. With Artificial Intelligence in question,
success and failure are the same sides of the coin. Technology also has some disadvantages and
challenges related to it. In this article, we’ll discuss some problems of artificial intelligence and
its solutions.

You’ll find a lot of information on the Internet about artificial intelligence and its applications.
But not a lot of attention has been given to the challenges of artificial intelligence. Here are some
of the artificial intelligence challenges:

 Building trust:
AI is all related to science and algorithms, which lies on the technical side. People who are
completely unaware of these algorithms and technology that lies behind the working of
Artificial intelligence find it difficult to understand its functioning.
Here is how artificial intelligence can face trust issues with humans, in spite of its ability to
cut down on tasks. It is a basic human psychology that we often neglect something that we
don’t understand.
We as humans tend to stay away from anything complicated. And artificial intelligence being
related to huge data, data science and algorithms, there are times when users do not grasp
these concepts.

 AI human interface:
The challenge here is the shortage of data science skills within humans to get maximum
output from artificial intelligence. As for the businesses, there is a shortage of advanced skills.

MGITER/CE/2018-19 Page 25
Artificial Intelligence (2180703) 150330107077

Business owners need to train their professionals to be able to leverage the benefits of this
technology.Statistics reveal that 55% of survey respondents felt the biggest challenge was the
changing scope of human jobs when everything will be automated.
 Investment:
Another challenge of artificial intelligence is that not all business owners or managers are
willing to invest in it. The funds required to set up and implement Artificial Intelligence is
very high, thus not every business owner or organization can invest in it or can try it for their
own business.
 Software malfunction:
No technology or human is perfect. In case of software or hardware crashes, it is difficult to
put a finger on what went wrong. On the other hand, tasks performed by humans can be
traced.
However, with machines and inbuilt algorithms in the picture, it is difficult to blame
someone or find the cause of a software/hardware crash. A recent example of this is the self-
driving cars that took the life of a pedestrian.
 AI can’t replace every task:
Ever since AI made its way into our lives, we have a notion that all tasks, minute or a
gigantic, can be managed by artificial intelligence. However, this can be true to a certain
extent. But not all the tasks can be undertaken by AI.
AI is more like a tool that helps increase the productivity of a task. It has the ability to replace
all the worldly tasks with machines and lets you do more productive tasks with your time.
This is a tool that strengthens and boost the performance and efficiency of an average worker.
 Higher expectations:
AI could have serious issues with the expectations of the people around. People, in general,
don’t have a detailed understanding of how AI works and hence they have extremely high
expectations; some of which are not even possible.
Humans have a tendency to expect high from something that is trending and the outputs from
it are also going to be excellent. However, like any other technology, there are certain
limitations associated with AI.
Experts belonging to various industries are pretty sure that artificial intelligence will rule the
next era, but there are some challenges that are a problem for artificial intelligence.

MGITER/CE/2018-19 Page 26
Artificial Intelligence (2180703) 150330107077

As a matter of fact, artificial intelligence has seen much hype in the market. However, AI is
still in its initial phase. After reading this blog, we hope you have a better idea about the
future of artificial intelligence.

3) How can AI be used to develop better search engine?

Search engines are incredible. Its algorithms and a lot of ideas from a lot of brilliant people. And
we’ve started to wonder: with all the brilliant minds behind them, to what extent are search
engines using artificial intelligence?

Thanks to those same search engines, I was able to find some great research explaining how
search engines use artificial intelligence.

 Search Engines Use Artificial Intelligence For Quality Control:


Back in the day, certain SEO “specialists” beat the system with shady practices that we’ve
come to know as “black hat SEO techniques.” These include aggressive keyword stuffing,
cloaking, invisible text—the list goes on.
Of course, this was damaging to search engines because the pages that were at the top of their
results weren’t necessarily the highest quality content.
Nowadays, they’ve updated their algorithms and use AI to separate the high quality content
from the low quality spam. We suspect that as AI progresses, it will completely take over this
responsibility and remove the need for human quality rates entirely.
 Search Engines Use AI To Create Ranking Algorithms:
Not only does artificial intelligence protect search engines from manipulation, but it also
helps them with their ranking algorithms.
It’s impossible to tell how big of a role AI plays in this, but search engines definitely use
artificial intelligence to improve their ranking algorithms.
To get a little more technical, this specific area of artificial intelligence involves learning to
rank algorithms. Machines are taught to create an optimal list from a set of possible outcomes,
learning from each of the variables over time.
For example, if one result on a search engine is ranking third but has a higher click through
rate than the options above it, the search engine would learn from this anomaly and bump
that result to the top.
 Ways to Benefit from AI and Search Engine Optimization:
1. Keywords are dead, intent is not:

MGITER/CE/2018-19 Page 27
Artificial Intelligence (2180703) 150330107077

Google moved beyond keywords a few years ago. This process intensified as users
explored different devices to use for their searches.
For example, you can see a lot of variation between a voice search on a mobile device
and a text search on a desktop computer.
Artificial Intelligence helps search engines match their needs. Every need search adds a
data point to help them improve their understanding of how humans search the web.
The AI is getting so smart that even Google and Bing have trouble ranking their own
products first on search engines today.
As you can see from the search below for web analytics, Google Analytics ranks near the
bottom of the page.
This is a huge problem for Google as they had trouble competing on their own search
engine to rank higher. If Google struggles with this, it means other companies must be
even more on the ball if they want to get the search traffic they need for their business.
Experts agree it is vital to avoid keyword stuffing and other black hat strategies that no
longer work.
Instead, as Anil Agarwal from BloggersPassion.com said, “User intent is still a top
priority. If you’re not focusing on giving the best experience to your target audience
through your content, no matter what tactics you adopt, they are of no use.”
The best way to engage consumers is to write naturally. When you speak like a human,
people who search like humans find your content. This was a problem early on in search.
Users could stuff in some keywords and the gobbled gook that came up was enough to
fool Google’s search engine to rank them high.
Factors like location, date, time, and device make the intent of a search different for each
user.
If you research the new Star Wars movie from your desktop then you want to learn more
about the movie; check the reviews, see the trailer.
However, if you then check out the movie on your phone, it is more likely you want to
know where the nearest movie theatre is and the times for the movies.
This is the power of intent. It is the reason AI plays such a vital role in search engine
optimization today. The computer must read all these factors in addition to the searchers
query to come up with the best information.

2. Predict what they do next

MGITER/CE/2018-19 Page 28
Artificial Intelligence (2180703) 150330107077

It is not only enough to know the users’ intent for their search. They also want to know
what users want to do after they finish searching. For example, what do users do after
they go through your content?
For example, if you search for the phrase characters in game of thrones the first result is
Wikipedia.
This should not be surprising, because Wikipedia not only lists the Game of Thrones
characters. They also have links directly underneath this for secondary characters like the
High Sparrow and SibelKikelli (Shae) in the movie.
The importance here is that using Schema data Wikipedia is predicting what other titbits
of information is important to searchers.
Google wants sites that keep your attention. This means improving the time on site as
well as decreasing the bounce rate to your website.
Visitors who stay for 3-5 seconds and bounce off to another site are not valuable to
Google and you, because your content is not relevant or good enough for them to keep
looking at right now.
Think of sites you visit and 30 minutes later you wonder where all the time went? You
just went down the rabbit hole of great content on a website. Your site needs to deliver
this type of user experience.
Google uses this information to find how valuable your site is to users.
3. Understand the buyer cycle
If you want to get users excited about your content, then segment your content to specific
phases of the buying cycle.
Users typically go through three phases of the buying process: Curiosity, Interest, and
Decision. The names vary a little if you are reading about this on Hub Spot or Facebook.
However, the process is similar.

MGITER/CE/2018-19 Page 29

You might also like