Professional Documents
Culture Documents
Omar Ahmed Fahmy Ahmed Omar Ayman Ahmed Nasr Omar Ahmed Saad Ali
dept. of Electronics and Electrical dept. of Electronics and Electrical dept. of Electronics and Electrical
Communications Engineering Communications Engineering Communications Engineering
Cairo University Cairo University Cairo University
Giza, Egypt Giza, Egypt Cairo, Egypt
omar.ahmed.fahmy2000@gmail.com omar.h142000@gmail.com omars98.5@gmail.com
Omar Adel Ahmed Mohamed Omar Hossam Eldin Fathy Ali
dept. of Electronics and Electrical Omar Ahmed Mostafa Ahmed dept. of Electronics and Electrical
Communications Engineering dept. of Electronics and Electrical Communications Engineering
Cairo University Communications Engineering Cairo University
Cairo, Egypt Cairo University Cairo, Egypt
omaradelkhedr@gmail.com Cairo, Egypt omar21hossam@gmail.com
Mohamed Yasser Mohamed Ali mory2018m@gmail.com Mohamed Mohamed Zaky Mohamed
dept. of Electronics and Electrical dept. of Electronics and Electrical
Communications Engineering Communications Engineering
Cairo University Cairo University
Giza, Egypt Cairo, Egypt
modiyasser30@gmail.com mohamedzaky177@gmail.com
Abstract—Tic-Tac-Toe is a very well-known pencil-and- thinking patterns. Tic tac toe is a game of predictability.
paper game that is popular among all age groups. It is held Actions are believed to be very important and predictable.
between two players, where each player must choose either ‘X’ This predictability helps to develop children's strategic
or ‘O’ and the winner is the one who succeeds in placing 3 thinking. They can learn through observation what their
successive marks (of their respective marks) either vertically, opponents’ next move is and think how to block them. This
horizontally or diagonally. In this paper, A machine-learning- could be considered as a simple and effective version of
based Tic-Tac-Toe game is approached, where instead of just chess. Children think more logically in order to figure out
having two human players playing against each other, an what they can do to win the game. It is a simple game where
artificial Intelligence (AI) can be used for playing as a single
players soon discover that optimal moves from both sides
player mode (i.e. a player against an AI). The AI is taught to
make choices and choose the appropriate moves that win it the
will always lead to a draw. In other words, a game between
game, which is –basically- the idea of machine learning. The two expert players will always end up with a draw. Hence, it
concept of the game theory is based on the minimax algorithm is more popular among children who have not yet
which draws the ideal scenario for the AI not to lose any game. discovered the perfect strategy. So, how can we take the
This results in an unbeatable AI, where the game ends in a idea of the game to the next level from just being a pencil-
draw in the worst case, when the player is playing optimally. and-paper game between two human beings to be including
Once the player makes a mistake, the AI takes the advantage to an interactively thinking Artificial intelligence (AI)? How
win the game. can we make use of machine learning science and convince
the AI to make the right choices to avoid losing? How can
Keywords—decision theory, combinatorial game theory, we take in consideration every single possibility in order to
minimax algorithm, game tree. build an unbeatable AI? This is what we are intending to
approach in this research. We aim to minimize the
I. INTRODUCTION computational time by using a suitable machine-learning for
the purpose. We need to teach the AI how to think and how
Tic tac toe is a pencil-and-paper game that has been to choose the next move, which is the main idea of
known for many years. It is a game which is played between “Machine-Learning”.
two players, X and O, and whoever succeeds in placing
three of their respective mark win the game. There are three
possible types of moves at the beginning of the game, II. LITERATURE SURVEY
namely – Centre, Corner and Edge. As shown in Fig. 1. Tic tac toe is a classic game that has been known for an
position 4 is the “Centre”, (0,2,6,8) are the “Corners” and exceptionally long time. In fact, games that are played on a
(1,3,5,7) are the “Edges”. three-in-a-row board had their origin in Egypt, where traces of
these games’ boards have been actually found on ceiling tiles
from around 1300 BCE. The game has been called by many
names over time, such as “X's and O's”," “X-e O-zees” and
“Boxin' Oxen”. Its name can even differ from one country to
another. The game is named “Tic-Tac-Toe” in the US,
“Noughts and Crosses” in the UK and “Twiddles and Bears” in
Norway. The name which is recognized the most in many
countries is “Tic-Tac-Toe” which has other accepted spellings
as tick tack toe, tick tat toe and tit tat toe depending on the
region and the country you are in. Around the first century BC,
Fig. 1. Representation of cells in a 3x3 grid. an early version of the game was played in the Roman Empire.
Playing tic tac toe helps teaching computational thinking Their version was entirely different and more complicated
skills when played by school aged students, according to a
study [1]. The study shows that these kinds of games help
young children to better draw out and articulate algorithmic
than the version we know today. It was called Terni Lapilli player, assuming that the opponent is also playing
[2] back then and each player had only three pieces to play optimally. The players are called maximizer and minimizer.
with instead of possessing any number of pieces, so in order As the name suggests, the maximizer aims to get the highest
to keep playing, both players had to move these pieces possible score, while the minimizer does the opposite.
around. In addition to the Romanian civilization, tic tac toe’s Hence, each board state during the game has a certain value.
markings have been also found in many places in Rome. It is given a positive value if it’s the maximizer’s turn and a
However, computational intelligence techniques were first negative value for the minimizer’s. Fig. 2. shows an
used in games in 1952 [3]. A scientist called Samuel was example that illustrates how minimax works. Consider a
able to apply the first computational algorithm to a board
game state where the maximizer player needs to decide
game known as Checkers. Without human intervention,
whether to go left or right, assuming the opponent is playing
through just observing the sequences that led to a win and
the sequences that led to a loss and using the very little and optimally. Since minimax is a backtracking algorithm, it
limited hardware tools at that time, the algorithm was able to would try all possible moves, then backtracks and makes a
learn and apply strategies good enough that it was even able decision. The minimizer has two choices between 3 and 5
to beat its own creator. After the early success of Samuel, a on the left sub tree, and between 2 and 9 on the right sub
computer scientist developer called Alexander S. Douglas tree. The maximizer’s choice depends on what the
was able to create the first ever computerized version of tic minimizer will choose in both sub trees. Being the
tac toe in 1959. This was the first tic tac toe video game that minimizer, it will choose the least of any given values;
had an AI embedded inside. He generated an efficient hence it will choose 3 on the left sub tree and 2 on the right
strategy for not having to lose a game even once. This was sub tree. Now it is the maximizer’s turn which chooses the
the first AI to be embedded in a tic tac toe game. In 1975, most of any given values. The two choices for the
MIT students used tic tac toe to build a tinkertoy computer maximizer are 3 on the left and 2 on the right; hence it will
to illustrate the computational power of Tinkertoy elements. choose 3. So, the optimal move for the maximizer in this
A tinkertoy computer is a computer which is made only of case is to go left.
tinkertoys, which was able to play tic tac toe games
perfectly. Accordingly, the computer was placed at the
Museum of Science in Boston. Then, research in the field of
computational intelligence remained silent for a long time.
But as a part of artificial intelligence research, some
researchers started to apply many classical AI techniques to
board games such as Checkers and Chess. Eventually, this
type of research led to the very popular victory of a Chess
computer - known as deep blue [4] - against the world chess
champion Kasparov in 1997. Later, a scientist called
Hochmuth used a genetic algorithm to develop an ideal tic
tac toe strategy, which does not lose a single game. He was Fig. 2. Minimax algorithm working principle.
able to conclude that there exist 827 different unique game
states and hence concentrated on finding a no-loss strategy. So, it can be concluded that the minimax algorithm
The study reported a single no-loss strategy, but it did not works according to the flow char in Fig. 3. The algorithm
provide a detailed description for that strategy to know its can be thought of as a representation of the human thought
properties. of saying “OK, if I make this move, then my opponent will
block me with that move, but if I make that one, it will
After analyzing some of those previously applied definitely lead to a win. So, this is the right move to make”.
strategies using various algorithms and comparing them
with the existing methodologies, in this paper, our goal is to
revisit the use of the minimax algorithm – which will be
later discussed in detail – which proved to be the perfect
strategy and the most efficient algorithm in finding a no-loss
strategy and creating an unbeatable AI.