80% found this document useful (5 votes)
6K views11 pages

A Project Report On: Tic Tac Toe Game'

The document is a project report on implementing a Tic Tac Toe game using the minimax algorithm. It includes an acknowledgement, preface, and sections on what Tic Tac Toe is, the minimax algorithm used, the utility function, properties and advantages/disadvantages of minimax, a comparison to alpha-beta pruning, references, and a conclusion stating the game was successfully implemented with minimax.

Uploaded by

yash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
80% found this document useful (5 votes)
6K views11 pages

A Project Report On: Tic Tac Toe Game'

The document is a project report on implementing a Tic Tac Toe game using the minimax algorithm. It includes an acknowledgement, preface, and sections on what Tic Tac Toe is, the minimax algorithm used, the utility function, properties and advantages/disadvantages of minimax, a comparison to alpha-beta pruning, references, and a conclusion stating the game was successfully implemented with minimax.

Uploaded by

yash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

A Project Report on

‘Tic Tac Toe Game’

Subject – Data Structures and Algorithms


Course Code – CSE2003

Submitted by – Yash Rastogi

Under the supervision of Prof. Gopinath M. P.

1
ACKNOWLEDGEMENT
I would like to express my gratitude and thanks to my Professor Gopinath M. P. who
gave me the golden opportunity to do this wonderful project on the topic Tic Tac Toe
Game using Minimax Algorithm.

He was the one who introduced me to this topic, that helped me in doing a lot of
Research, and I came to know about so many new things.

I am really thankful to him.

I would also like to thank my parents, friends and teachers who helped me a lot in
completing this project within the specified time period.

2
PREFACE

This report is an introduction to the Tic-Tac-Toe game in C++ programming.


Anybody, who doesn’t know even the basics of Tic Tac Toe in C++, will certainly be
able to understand and gain great knowledge from this report. The core theme of
the project focuses on the development of Tic Tac Toe game in C++ using minimax
algorithm.
The report also contains the strategy used in making Tic Tac Toe game,
Comparison with different kinds of algorithm, advantages of minimax algorithm.

3
CONTENTS

ACKNOWLEDGEMENT.............................................................................. 2
PREFACE ....................................................................................................3
WHAT IS TIC TAC TOE ............................................................................... 5
ALGORITHM USED IN GAME ...................................................................... 6
UTILITY FUNCTION .................................................................................... 8
PROPERTIES OF MINIMAX ,
ADVANTAGE, DISADVANTAGE .................................................................9
COMPARISON WITH
ALPHA BETA PRUNING ............................................................................... 10
REFERENCES ............................................................................................. 12
CONCLUSION .............................................................................................. 13

4
WHAT IS A TIC TAC TOE GAME?

Tic-tac-toe is not a very challenging game for human beings. If you’re an enthusiast,
you’ve probably moved from the basic game to some variant like three dimensional
tic-tac-toe on a larger grid. If you sit down right now to play ordinary three-by-three tic-
tac-toe with a friend, what will probably happen is that every game will come out a tie.

Both you and your friend can probably play perfectly, never making a mistake that
would allow your opponent to win. But can you describe how you know where to move
each turn? Most of the time, you probably aren’t even aware of alternative
possibilities; you just look at the board and instantly know where you want to move.
That kind of instant knowledge is great for human beings, because it makes you a fast
player. But it isn’t much help in writing a computer program. For that, you have to
know very explicitly what your strategy is.

5
ALGORITHM USED IN TIC TAC TOE
Algorithm used here is minimax algorithm to compute the optimal move of a player
and decide the winner.

Minimax is a kind of backtracking algorithm that is used in decision making and game
theory to find the optimal move for a player, assuming that your opponent also plays
optimally. It is widely used in two player turn based games such as Tic-Tac-Toe,
Backgamon, Mancala, Chess, etc.

In Minimax the two players are called maximizer and minimizer. The maximizer tries to
get the highest score possible while the minimizer tries to get the lowest score
possible while minimizer tries to do opposite.

Every board state has a value associated with it. In a given state if the maximizer has
upper hand then, the score of the board will tend to be some positive value. If the
minimizer has the upper hand in that board state then it will tend to be some negative
value. The values of the board are calculated by some heuristics which are unique for
every type of game.

6
GAME TREE

MINIMAX TERMINOLOGY
 Utility function: the function applied to leaf nodes
 Backed up values
 Of a max position- the value of its largest successor
 Of a min position- the value of its smallest successor.

MINIMAX PROCEDURE
 Search down several levels.
 Apply utility function to leaf nodes.
 Back up values all the way up to the root node.
 That node selects the move.
7
UTILITY FUNCTION
 Let p be a position in the game
 Define the utility function f(p) by
 F(p)=
 largest positive number if p is a win for computer
 smallest negative number if p is a win for opponent
 RCDC – RCDO
 where RCDC is number of rows, columns and diagonals in which player 1 could
still win
 and RCDO is number of rows, columns and diagonals in which player 2 could
still win.

8
PROPERTIES OF MINIMAX
It is complete algorithm if tree is finite. It is optimal if you are playing with an optimal
player.
Time complexity computed here is O(bm). Space complexity computed here is O(dm).
Where b is the number of legal moves available for a player at each point and d is the
maximum depth of the tree.

ADVANTAGE
The Minimax algorithm helps find the best move, by working backwards from the end
of the game. At each step it assumes that player A is trying to maximize the chances
of its winning, while on the next turn player B is trying to minimize the chances of A’s
winning.

DISADVANTAGE
A disadvantage of the minimax algorithm is that each board state has to be visited
twice: one time to find its children and a second time to evaluate the heuristic value.

9
COMPARISON WITH ALPHA-BETA
PRUNING
Alpha beta procedure speeds up the depth first minimax search.
Alpha: best value that the maximizer can guarantee at that level or above.
Beta: best value that the minimizer can guarantee at that level or above.

Alpha-beta pruning does not affect final result. This means that it gets the exact same
result as does full minimax. This allows us to search much faster and even go into
deeper levels in the game tree. It cuts off branches in the game tree which need not to
be searched because there already exists a better move. Good move ordering
improves effectiveness of pruning.

With "perfect ordering," time complexity = O(bm/2)


It doubles the depth of search.

10
REFERENCES

 Google.com
 Wikipedia.org
 Stackoverflow.com
 Introduction to algorithms by Thomas H. Cormen

CONCLUSION

I have successfully implemented the Tic-Tac-Toe game in C++ language with the help
of minimax algorithm.

11

You might also like