Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
726 views20 pages

Tic Tac Toe

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 20

Tic Tac Toe Genius

Artificial Intelligence (CU6051)

Submitted by: Submitted to:


Arjun Gurung (14046958) Mr. Sukant Kumar Sahu
Kiran Shahi (14046931) Module Leader
Date: 19th January, 2017
Aims And Objectives:
1. Introduction of the topic.

2. Current Scenario

3. System Functionality

4. Algorithm

5. Pseudocode

6. Future Enhancement

7. Reference
Introduction
Tic Tac Toe, very popular and easy to play.

Two players game.

3x3 grid most commonly used.

A paper and pen based game.


Why Tic Tac Toe

Rules for tic tac toe game is simple enough that we don't need an
elaborate analysis of game configurations.

Despite being a simple game, the basic AI principles shown here can be
applied to more complicated games such as checkers, Go and even
chess.
Present Scenario
• Many versions of tic tac toe like 3x3, 4x4 and even 9x9.

• Can be made on various platforms like Python, Java, C and even


JavaScript Canvas.

• Not so complex architecture.


Program Flow of Tic Tac Toe Genius
Start

NO Check Yes
winning
point

Check
winning Take
move Yes move
for User

Take move
NO
Check
corner
space Yes
Take move
NO

Check Ask
Center User
to
NO Yes take
Take move move
Check
Side

NO
Yes
Check Take move
diagona
l for (X)

Yes

NO Check
diagona
l for (0)

NO System
wins
Game is
draw
Yes
User
wins
End
Functionality
• How to play Tic-Tac-Toe game?

• Some guiding steps to play the game are:


• The game is played between two players
• Both players choose their respective symbols to mark
• Player 1 starts the turn by placing his/her symbol on any of the nine squares
• Then player 2 marks the turn by placing his/her symbol on the empty squares
• Both players make their turns alternately
• If any player gets the three respective symbols in a horizontal, vertical or
diagonal row wins the game
Functionality
Winning Combinations in game:

In a tic-tac-toe game there are 8 possibilities to win the game. The


possibilities are getting the three combinations horizontally, three
combinations vertically or two combinations diagonally as shown in the
figure below. Hence, the easiest way to find the way to determine the
winner of the game is to check for these eight combinations as the
game goes on.
Functionality
Winning Combinations in game:
Game Strategies
• Win: If you have two in a row, play the third to get three in a row.
• Block: If the opponent has two in a row, play the third to block them.
• Fork: Create an opportunity where you can win in two ways.
• Block Opponent's Fork:
• Option 1: Create two in a row to force the opponent into defending, as long as it doesn't
result in them creating a fork or winning. For example, if "X" has a corner, "O" has the
centre, and "X" has the opposite corner as well, "O" must not play a corner in order to
win. (Playing a corner in this scenario creates a fork for "X" to win.)
• Option 2: If there is a configuration where the opponent can fork, block that fork.
• Centre: Play the centre.
• Opposite Corner: If the opponent is in the corner, play the opposite corner.
• Empty Corner: Play an empty corner.
• Empty Side: Play an empty side.
Algorithm Chosen
Mini-Max Algorithm

• Best suited for game with 2 player.


• To find a path from the starting position to a goal position.
• Calculate all possible game states by examining all opposing moves.
• Determine the next move against best play [opponent].
Game tree of Tic Tac Toe
Algorithm
• Step 1: START
• Step 2: Check winning move for system (X). If there is such move, take it and
go to Step 7. Else go to Step 3.
• Step 3: Check wining move for user (O). It there is such move, then block the
player and go to Step 7. Else go to Step 4.
• Step 4: If there are corner spaces (i.e. 1, 3, 7, 9), take it and go to Step 7.
Else go to Step 5.
• Step 5: If there is center position, take it and go to step 7. Else go to Step 6.
• Step 6: If there are side positions (i.e. 2,4,6,8), take it and go to Step 7. Else
go to step 8. (Since there are no spaces left to move.)
• Step 7: Ask user to take a move and go to step 2.
Algorithm
• Step 8: Check system move (X) is in a vertical/horizontal/diagonal form.
If it is there the system will win. And go to step 11. Else go to step 9.
• Step 9: Check user’s move (O) is in a vertical/horizontal/diagonal form. If
it is there the system will lose. And go to step 11. Else go to step 10.
• Step 10: Game is draw and go to step 11:
• Step 11: END
Pseudocode
Find the path READ move from
CALL minimax User
DO ELSE IF available move is
GET available move centre space
IF available move is SET move to available
winning move move
SET move to READ move from User
available move
READ move ELSE IF available move is side
from User space
ELSE IF available move is SET move to available
winning move for User space
SET move to READ move from User
available move
READ move from ELSE
User CALL Check Result
ELSE IF available move is
corner spaces END IF
SET move to END DO
available move
Pseudocode
CALL Check Result
CheckScore
DO
CALL checkScore IF System move (X) is
DO diagonal
SET result win
IF System wins
CALL Check Score
Return 1 ELSE IF User move (0) is
ElSE IF User wins in diagonal
SET result lose
Return -1
CALL Check Score
ELSE ELSE
Return 0 SET result draw
CALL Check Score
END IF
END IF
END DO END DO
Further Enhancement
• More number of winning strategies.

• Implementation of MINMAX algorithm into other games such as


checker, Go and even chess.

• Use of other Algorithms like Heuristic Search(BFS and DFS)


Conclusion
• An AI based game ‘Toc Tac Toe Genius’.

• Very popular and Entertaining.

• Not so complex use of Algorithm and Pseudocode.

• Number of possible winning combinations like horizontal, vertical and


Diagonal.
Any Questions?
References
• Tic-tac-toe AI - Java Game Programming Case Study. 2017. Tic-tac-toe AI - Java Game
Programming Case Study. [ONLINE] Available at:
https://www.ntu.edu.sg/home/ehchua/programming/java/JavaGame_TicTacToe_AI.html. [Accessed
10 January 2017].

• Jason Fox. 2017. Tic Tac Toe: Understanding The Minimax Algorithm. [ONLINE] Available at:
http://neverstopbuilding.com/minimax. [Accessed 11 January 2017].

• How to use Minimax's algorithm to make a Tic-Tac-Toe - Quora. 2017. How to use Minimax's
algorithm to make a Tic-Tac-Toe - Quora. [ONLINE] Available at: https://www.quora.com/How-do-I-
use-Minimaxs-algorithm-to-make-a-Tic-Tac-Toe. [Accessed 10 January 2017].

• The Ludologist. 2017. 255,168 ways of playing Tic Tac Toe – The Ludologist. [ONLINE] Available at:
https://www.jesperjuul.net/ludologist/255168-ways-of-playing-tic-tac-toe. [Accessed 6 January
2017].

You might also like