You are on page 1of 6

C++ PROJECT ON TIC TAC

TOE GAME

Made by:-

Rutvik reshamwala (reg no.-RA1611003010768)


Yash keswani (reg no.-RA1611003010847)
Aaradhya Shukla (reg no.-RA1611003011147)
OBJECTIVE :

•Tic-tac-toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their
marks in a horizontal, vertical, or diagonal row wins the game.

• The following example game is won by the first player, X:

•Game of Tic-tac-toe, won by X


•Players soon discover that best play from both parties leads to a draw. Hence, tic-tac-toe is most often played by young children.

•Because of the simplicity of tic-tac-toe, it is often used as a pedagogical tool for teaching the concepts of good sportsmanship and the branch of artificial intelligence that
deals with the searching of game trees. It is straightforward to write a computer program to play tic-tac-toe perfectly, to enumerate the 765 essentially different positions
(the state space complexity), or the 26,830 possible games up to rotations and reflections (the game tree complexity) on this space.[1]

•The game can be generalized to an m,n,k-game in which two players alternate placing stones of their own color on an m×n board, with the goal of getting k of their own
color in a row. Tic-tac-toe is the (3,3,3)-game.[2] Harary's generalized tic-tac-toe is an even broader generalization of tic tac toe. It can also be generalized as a nd game.
Tic-tac-toe is the game where n equals 3 and d equals 2.[3] If played properly, the game will end in a draw making tic-tac-toe a futile game.[4]
ALGORITHM :

• A description for the algorithm, assuming X is the "turn taking player," would look something like:
• If the game is over, return the score from X's perspective.
• Otherwise get a list of new game states for every possible move
• Create a scores list
• For each of these states add the minimax result of that state to the scores list
• If it's X's turn, return the maximum score from the scores list
• If it's O's turn, return the minimum score from the scores list
• You'll notice that this algorithm is recursive, it flips back and forth between the players until a final score is found.
• Let's walk through the algorithm's execution with the full move tree, and show why, algorithmically, the instant winning move
will be picked:
ALGORITHM CONTD. :-

• It's X's turn in state 1. X generates the states 2, 3, and 4 and calls minimax on those states.
• State 2 pushes the score of +10 to state 1's score list, because the game is in an end state.
• State 3 and 4 are not in end states, so 3 generates states 5 and 6 and calls minimax on them, while state 4 generates states 7 and 8 and calls
minimax on them.
• State 5 pushes a score of -10 onto state 3's score list, while the same happens for state 7 which pushes a score of -10 onto state 4's score list.
• State 6 and 8 generate the only available moves, which are end states, and so both of them add the score of +10 to the move lists of states 3 and
4.
• Because it is O's turn in both state 3 and 4, O will seek to find the minimum score, and given the choice between -10 and +10, both states 3 and 4
will yield -10.
• Finally the score list for states 2, 3, and 4 are populated with +10, -10 and -10 respectively, and state 1 seeking to maximize the score will chose
the winning move with score +10, state 2.
• That is certainly a lot to take in. And that is why we have a computer execute this algorithm.
METHODOLOGIES

Tic tac toe game display


Swapping content
OUTPUT:

You might also like