Download as pdf or txt
Download as pdf or txt
You are on page 1of 52

TIK-TAC-TOE

Problem in AI

1
TIK-TAC-TOE
Problem in AI

2
TIK-TAC-TOE
Problem in AI

3
TIK-TAC-TOE
Problem in AI

4
TIK-TAC-TOE
Problem in AI

5
1. Curricular
Aspects

Feedback

6
TIK-TAC-TOE
Problem in AI

7
TIK-TAC-TOE
Problem in AI

8
TIC-TAC-TOE
Problem/Game
in AI

9
TIK-TAC-TOE
Problem/Game
in AI

10
TIK-TAC-TOE
Problem/Game
in AI

11
TIK-TAC-TOE
Problem in AI

12
TIK-TAC-TOE
Problem/Game
Tree in AI

13
TIK-TAC-TOE
Problem/Game
Tree in AI

14
TIK-TAC-TOE
Problem/Game
Tree in AI

15
CHESS
Problem in AI

16
CHESS
Problem in AI

17
CHESS
Problem in AI

18
CHESS
Problem in AI

19
CHESS
Problem in AI

20
Chess Problem: Definition:
• It is a normal chess game. In a chess problem, the start is the initial
configuration of chessboard.
• The final state is the any board configuration, which is a winning position
CHESS for any player.
• There may be multiple final positions and each board configuration can be
Problem in AI thought of as representing a state of the game. Whenever any player
moves any piece, it leads to different state of game.

• The above figure shows a 3x3 chessboard with each square labeled with integers 1 to 9.
• We simply enumerate the alternative moves rather than developing a general move
operator because of the reduced size of the problem.
• Using a predicate called move in predicate calculus, whose parameters are the starting
and ending squares, we have described the legal moves on the board.
• The final state is the any board configuration, which is a winning position for any player.
21
Chess Problem (Cont…)
• For example, move (1, 8) takes the knight from the upper left-
hand corner to the middle of the bottom row.
• While playing Chess, a knight can move two squares either
CHESS horizontally or vertically followed by one square in an orthogonal
Problem in AI direction as long as it does not move off the board.

The all possible moves of figure are as follows.

Move (1, 8) move (6, 1)

Move (1, 6) move (6, 7)

Move (2, 9) move (7, 2)

Move (2, 7) move (7, 6)

Move (3, 4) move (8, 3)


22
Move (3, 8) move (8, 1)

Move (4, 1) move (9, 2)


CHESS
Move (4, 3) move (9, 4)
Problem in AI
• The above predicates of the Chess Problem form the knowledge base for this problem.
• An unification algorithm is used to access the knowledge base.
• Suppose we need to find the positions to which the knight can move from a particular
location, square 2.
• The goal move (z, x) unifies with two different predicates in the knowledge base, with
the substitutions {7/x} and {9/x}.
• Given the goal move (2, 3), the responsible is failure, because no move (2, 3) exists in
the knowledge base.

Comments: In this game a lots of production rules are applied for each move
of the square on the chessboard. A lots of searching are required in this game.

23
Implementation of algorithm in the knowledge base is very important.
Brute Force
and
Exhaustive
Search
Problem in AI

24
Brute Force
and
Exhaustive
Search
Problem in AI

25
Brute Force
and
Exhaustive
Search
Problem in AI

26
Brute Force
and
Exhaustive
Search
Problem in AI

27
Brute Force
and
Exhaustive
Search
Problem in AI

28
Brute Force
and
Exhaustive
Search
Problem in AI

29
Brute Force
and
Exhaustive
Search
Problem in AI

30
Brute Force
and
Exhaustive
Search
Problem in AI

31
Brute Force
and
Exhaustive
Search
Problem in AI

32
Brute Force
and
Exhaustive
Search
Problem in AI

33
Brute Force
and
Exhaustive
Search
Problem in AI

34
Brute Force
and
Exhaustive
Search
Problem in AI

35
Brute Force
and
Exhaustive
Search
Problem in AI

36
Brute Force
and
Exhaustive
Search
Problem in AI

37
Brute Force
and
Exhaustive
Search
Problem in AI

38
Brute Force
and
Exhaustive
Search
Problem in AI

39
Brute Force
and
Exhaustive
Search
Problem in AI

40
Brute Force
and
Exhaustive
Search
Problem in AI

41
Brute Force
and
Exhaustive
Search
Problem in AI

42
Brute Force
and
Exhaustive
Search
Problem in AI

43
Brute Force
and
Exhaustive
Search
Problem in AI

44
Brute Force
and
Exhaustive
Search
Problem in AI

45
Brute Force
and
Exhaustive
Search
Problem in AI

46
Brute Force
and
Exhaustive
Search
Problem in AI

47
Brute Force
and
Exhaustive
Search
Problem in AI

48
Depth First Search-

Depth First •Depth First Search or DFS is a graph traversal algorithm.


•It is used for traversing or searching a graph in a systematic fashion.
Search
•DFS uses a strategy that searches “deeper” in the graph whenever possible.
Problem in AI
•Stack data structure is used in the implementation of depth first search.

DFS Example-

Consider the following graph -

The depth first search traversal order of the above graph is - A, B, E, F, C, D 49


BFS vs DFS
S.No. Parameters BFS DFS
BFS Vs DFS 1. Stands for BFS stands for Breadth First Search. DFS stands for Depth First Search.
BFS (Breadth First Search) uses Queue
Problem in AI 2. Data Structure data structure for finding the shortest
DFS (Depth First Search) uses Stack
data structure.
path.
DFS is also a traversal approach in
which the traverse begins at the root
BFS is a traversal approach in which we
node and proceeds through the
3. Definition first walk through all nodes on the same
nodes as far as possible until we
level before moving on to the next level.
reach the node with no unvisited
nearby nodes.
BFS can be used to find a single source
shortest path in an unweighted graph In DFS, we might traverse through
4. Technique because, in BFS, we reach a vertex with a more edges to reach a destination
minimum number of edges from a source vertex from a source.
vertex.
Conceptual DFS builds the tree sub-tree by sub-
5. BFS builds the tree level by level.
Difference tree.
It works on the concept of FIFO (First In It works on the concept of LIFO (Last
6. Approach used
First Out). In First Out).
BFS is more suitable for searching vertices DFS is more suitable when there are
7. Suitable for
closer to the given source. solutions away from source. 50
BFS vs DFS
S.No. Parameters BFS DFS
BFS Vs DFS DFS is more suitable for game or
Problem in AI Suitability for
BFS considers all neighbors first and
puzzle problems. We make a
decision, and the then explore all
8. therefore not suitable for decision-
Decision-Trees paths through this decision. And if
making trees used in games or puzzles.
this decision leads to win situation,
we stop.
The Time complexity of BFS is O(V + E) The Time complexity of DFS is also
when Adjacency List is used and O(V^2) O(V + E) when Adjacency List is used
Time
9. when Adjacency Matrix is used, where V and O(V^2) when Adjacency Matrix
Complexity
stands for vertices and E stands for is used, where V stands for vertices
edges. and E stands for edges.
Visiting of
Here, siblings are visited before the Here, children are visited before the
10. Siblings/
children. siblings.
Children
Removal of The visited nodes are added to the
Nodes that are traversed several times
11. Traversed stack and then removed when there
are deleted from the queue.
Nodes are no more nodes to visit.
DFS algorithm is a recursive
In BFS there is no concept of
12. Backtracking algorithm that uses the idea of
backtracking.
backtracking
51
BFS vs DFS
S.No. Parameters BFS DFS
BFS Vs DFS DFS is used in various applications
BFS is used in various applications such
Problem in AI 13. Applications
as bipartite graphs, shortest paths, etc.
such as acyclic graphs and
topological order etc.
14. Memory BFS requires more memory. DFS requires less memory.
BFS is optimal for finding the shortest DFS is not optimal for finding the
15. Optimality
path. shortest path.
DFS has lesser space complexity
Space In BFS, the space complexity is more because at a time it needs to store
16.
complexity critical as compared to time complexity. only a single path from the root to
the leaf node.
17. Speed BFS is slow as compared to DFS. DFS is fast as compared to BFS.
Tapping in In BFS, there is no problem of trapping In DFS, we may be trapped in
18,
loops into infinite loops. infinite loops.
When the target is close to the source, When the target is far from the
19. When to use?
BFS performs better. source, DFS is preferable.

52

You might also like