SlideShare a Scribd company logo
tic- tac- toe in python
(using minimax algorithm)
PRESENTED BY:
ABDUS SUBHAN
1CR20EC003
AADITHYA D KUMAR
1CR20EC002
ABHISHEK KUMAR SINGH
1CR20EC006
Project Advisor :
PROF. JYOTI M.R.
Pre-requisites
 Python compiler
 Python programming
 Minimax Algorithm in Game Theory
strategy
1
 Optimal strategy for player X. In each grid, the shaded red X denotes the optimal move, and
the location of O's next move gives the next subgrid to examine. Note that only two sequences
of moves by O (both starting with center, top-right, left-mid) lead to a draw, with the remaining
sequences leading to wins from X.
A player can play perfect tic-tac-toe (win or draw) given they choose the first possible move
from the following list.
Win: If the player has two in a row, he or she can place a third to get three in a row.
Block: If the [opponent] has two in a row, the player must play the third himself or herself to
block them.
Fork: Creation of an opportunity where the player has two threats to win (two non-blocked lines
of 2).
strategy
1
 Blocking an opponent's fork:
Option 1: The player should create two in a row to force the opponent into defending, as
long as it doesn't result in them creating a fork. For example, if "X" has a corner, "O" has the
center, 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, the player should block
that fork.
Center: A player marks the center. (If it is the first move of the game, playing on a corner
gives "O" more opportunities to make a mistake and may therefore be the better choice;
however, it makes no difference between perfect players.)
Opposite corner: If the opponent is in the corner, the player plays the opposite corner.
introduction
1
 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 or 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. If played
optimally by both players, the game always ends in a draw, making tic-
tac-toe a futile game.
The Minimax Algorithm
1
 Minimax Algorithm is a decision rule formulated for two player zero-
sum games (Tic-Tac-Toe, Chess, Go, etc.).
 This algorithm sees a few steps ahead and puts itself in the shoes of its
opponent. It keeps playing and exploring subsequent possible states until
it reaches a terminal state resulting in a draw, a win, or a loss.
 Being in any of these possible terminal states has some utility for the AI
— such as being in a ‘Win’ state is good (utility is positive), being in a ‘Loss’
state is bad (utility is negative), and being in a draw in neither good nor
bad (utility is neutral).
algorithm
 In our execution of the Minimax algorithm for solving Tic-Tac-Toe, it
works by visualizing all future possible states of the board and
constructs it in the form of a tree. When the current board state is given
to the algorithm (the root of the tree), it splits into ’n’ branches (where
n denotes the number of moves that can be chosen by the AI/number
of empty cells where the AI can be placed). If any of these new states is
a terminal state, no further splits are performed for this state and it is
assigned a score the following way:
 Score = +1 (if AI wins) Score = -1 (if AI loses) Score= 0 (If a draw happens)
6
Architecture
3
9/28/2023
Pre-Requisite Before Coding
9/28/2023
Board
Display board
Play game
Check win:
1)Row win
2)Column win
3)Diagonal win
Check tie
Flip player
CODE
9/28/2023
9/28/2023
9/28/2023
9/28/2023
9/28/2023
9/28/2023
OUTPUT 1 (Row win)
9/28/2023
OUTPUT 2 (Column win)
9/28/2023
OUTPUT 3 (Diagonal win)
9/28/2023
OUTPUT 4 (Invalid inputs)
9/28/2023
APplications
1
Various game shows have been based on Tic-Tac-Toe and its variants:
On Hollywood Squares, nine celebrities filled the cells of the tic-tac-toe grid; players
put symbols on the board by correctly agreeing or disagreeing with a celebrity's
answer to a question. Variations of the show include Storybook Squares and Hip Hop
Squares.
In Tic-Tac-Dough, players put symbols up on the board by answering questions in
various categories, which shuffle after each player's turn.
In Beat the Teacher, contestants answer questions to win a turn to influence a tic-tac-
toe grid.
limitations
 The game cannot be played by more than one players.
 It is not a high level game.
 It doesn’t contain levels.
7
References
 https://youtu.be/BHh654_7Cmw
 Minimax Algorithm in Game Theory | Set 3 (Tic-Tac-Toe AI – Finding optimal
move)- Geeks for Geeks
https://www.geeksforgeeks.org/minimax-algorithm-in-game-theory-set-3-
tic-tac-toe-ai-finding-optimal-move/
 Tic Tac Toe AI with MiniMax using Python | Part 1: Programming Tic Tac Toe-
YouTube
https://www.youtube.com/watch?v=JC1QsLOXp-I
 Tic Tac Toe AI with MiniMax using Python | Part 2: Minimax- YouTube
https://www.youtube.com/watch?v=2Tr8LkyU78c 7
Thank You
24

More Related Content

PPTX
Artificial Intelligence- TicTacToe game
manika kumari
 
PPT
1.game
veeramakali
 
PDF
Stratego
Sergiu Redeca
 
PPT
Tic tac toe on c++ project
Utkarsh Aggarwal
 
PDF
Modelling and implementation of 9tka game with MaxN algorithm
TELKOMNIKA JOURNAL
 
PPT
problem-reduction-game-problemgmgntc.ppt
s0618614
 
PDF
AI Lesson 07
Assistant Professor
 
PPTX
tic-tac-toe: Game playing
kalpana Manudhane
 
Artificial Intelligence- TicTacToe game
manika kumari
 
1.game
veeramakali
 
Stratego
Sergiu Redeca
 
Tic tac toe on c++ project
Utkarsh Aggarwal
 
Modelling and implementation of 9tka game with MaxN algorithm
TELKOMNIKA JOURNAL
 
problem-reduction-game-problemgmgntc.ppt
s0618614
 
AI Lesson 07
Assistant Professor
 
tic-tac-toe: Game playing
kalpana Manudhane
 

Similar to 0-miniproject sem 4 review 1(1)(2).pptx (20)

PPT
Game Tree ( Oyun Ağaçları )
Alp Çoker
 
PPTX
python.pptx
sreeshanthSingarapu
 
PPTX
AI based Tic Tac Toe game using Minimax Algorithm
Kiran Shahi
 
PDF
Android application - Tic Tac Toe
Sarthak Srivastava
 
PDF
quarto
Matthew Kerner
 
DOCX
This is an individual project, to be completed on your own. It i.docx
abhi353063
 
PPT
Unit_I_Introduction(Part_III).ppt
ganesh15478
 
PDF
Aipapercpt
Praveen Kumar
 
PDF
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
info382133
 
PDF
AI Strategies for Solving Poker Texas Hold'em
Giovanni Murru
 
DOC
C++ projct
J M
 
PDF
Libratus
Anatol Alizar
 
PPTX
Tic Tac Toe ppt
SanchitRastogi15
 
PPT
Adversarial Search and Game-Playing .ppt
0fakerxfaker0
 
PDF
International journal of engineering issues vol 2015 - no 2 - paper1
sophiabelthome
 
PPT
Unit 2 Topic 6 Adversarggggial Search.ppt
ssuser470a6d1
 
PPTX
Adversarial Search
Megha Sharma
 
PPTX
5 Theory of Games 1. Special notes designed for students
aloksinghtanwar7720
 
PPTX
AI_Session 13 Adversarial Search .pptx
Guru Nanak Technical Institutions
 
PDF
MONTE-CARLO TREE SEARCH FOR THE “MR JACK” BOARD GAME
ijscai
 
Game Tree ( Oyun Ağaçları )
Alp Çoker
 
python.pptx
sreeshanthSingarapu
 
AI based Tic Tac Toe game using Minimax Algorithm
Kiran Shahi
 
Android application - Tic Tac Toe
Sarthak Srivastava
 
This is an individual project, to be completed on your own. It i.docx
abhi353063
 
Unit_I_Introduction(Part_III).ppt
ganesh15478
 
Aipapercpt
Praveen Kumar
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
info382133
 
AI Strategies for Solving Poker Texas Hold'em
Giovanni Murru
 
C++ projct
J M
 
Libratus
Anatol Alizar
 
Tic Tac Toe ppt
SanchitRastogi15
 
Adversarial Search and Game-Playing .ppt
0fakerxfaker0
 
International journal of engineering issues vol 2015 - no 2 - paper1
sophiabelthome
 
Unit 2 Topic 6 Adversarggggial Search.ppt
ssuser470a6d1
 
Adversarial Search
Megha Sharma
 
5 Theory of Games 1. Special notes designed for students
aloksinghtanwar7720
 
AI_Session 13 Adversarial Search .pptx
Guru Nanak Technical Institutions
 
MONTE-CARLO TREE SEARCH FOR THE “MR JACK” BOARD GAME
ijscai
 
Ad

Recently uploaded (20)

PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
PDF
5.Universal-Franchise-and-Indias-Electoral-System.pdfppt/pdf/8th class social...
Sandeep Swamy
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
mansk2
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PDF
Introducing Procurement and Supply L2M1.pdf
labyankof
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PDF
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
TumwineRobert
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Mithil Fal Desai
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
5.Universal-Franchise-and-Indias-Electoral-System.pdfppt/pdf/8th class social...
Sandeep Swamy
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
Week 4 Term 3 Study Techniques revisited.pptx
mansk2
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
Introducing Procurement and Supply L2M1.pdf
labyankof
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Cardiovascular Pharmacology for pharmacy students.pptx
TumwineRobert
 
Landforms and landscapes data surprise preview
jpinnuck
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Mithil Fal Desai
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Ad

0-miniproject sem 4 review 1(1)(2).pptx

  • 1. tic- tac- toe in python (using minimax algorithm) PRESENTED BY: ABDUS SUBHAN 1CR20EC003 AADITHYA D KUMAR 1CR20EC002 ABHISHEK KUMAR SINGH 1CR20EC006 Project Advisor : PROF. JYOTI M.R.
  • 2. Pre-requisites  Python compiler  Python programming  Minimax Algorithm in Game Theory
  • 3. strategy 1  Optimal strategy for player X. In each grid, the shaded red X denotes the optimal move, and the location of O's next move gives the next subgrid to examine. Note that only two sequences of moves by O (both starting with center, top-right, left-mid) lead to a draw, with the remaining sequences leading to wins from X. A player can play perfect tic-tac-toe (win or draw) given they choose the first possible move from the following list. Win: If the player has two in a row, he or she can place a third to get three in a row. Block: If the [opponent] has two in a row, the player must play the third himself or herself to block them. Fork: Creation of an opportunity where the player has two threats to win (two non-blocked lines of 2).
  • 4. strategy 1  Blocking an opponent's fork: Option 1: The player should create two in a row to force the opponent into defending, as long as it doesn't result in them creating a fork. For example, if "X" has a corner, "O" has the center, 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, the player should block that fork. Center: A player marks the center. (If it is the first move of the game, playing on a corner gives "O" more opportunities to make a mistake and may therefore be the better choice; however, it makes no difference between perfect players.) Opposite corner: If the opponent is in the corner, the player plays the opposite corner.
  • 5. introduction 1  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 or 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. If played optimally by both players, the game always ends in a draw, making tic- tac-toe a futile game.
  • 6. The Minimax Algorithm 1  Minimax Algorithm is a decision rule formulated for two player zero- sum games (Tic-Tac-Toe, Chess, Go, etc.).  This algorithm sees a few steps ahead and puts itself in the shoes of its opponent. It keeps playing and exploring subsequent possible states until it reaches a terminal state resulting in a draw, a win, or a loss.  Being in any of these possible terminal states has some utility for the AI — such as being in a ‘Win’ state is good (utility is positive), being in a ‘Loss’ state is bad (utility is negative), and being in a draw in neither good nor bad (utility is neutral).
  • 7. algorithm  In our execution of the Minimax algorithm for solving Tic-Tac-Toe, it works by visualizing all future possible states of the board and constructs it in the form of a tree. When the current board state is given to the algorithm (the root of the tree), it splits into ’n’ branches (where n denotes the number of moves that can be chosen by the AI/number of empty cells where the AI can be placed). If any of these new states is a terminal state, no further splits are performed for this state and it is assigned a score the following way:  Score = +1 (if AI wins) Score = -1 (if AI loses) Score= 0 (If a draw happens) 6
  • 10. Pre-Requisite Before Coding 9/28/2023 Board Display board Play game Check win: 1)Row win 2)Column win 3)Diagonal win Check tie Flip player
  • 17. OUTPUT 1 (Row win) 9/28/2023
  • 18. OUTPUT 2 (Column win) 9/28/2023
  • 19. OUTPUT 3 (Diagonal win) 9/28/2023
  • 20. OUTPUT 4 (Invalid inputs) 9/28/2023
  • 21. APplications 1 Various game shows have been based on Tic-Tac-Toe and its variants: On Hollywood Squares, nine celebrities filled the cells of the tic-tac-toe grid; players put symbols on the board by correctly agreeing or disagreeing with a celebrity's answer to a question. Variations of the show include Storybook Squares and Hip Hop Squares. In Tic-Tac-Dough, players put symbols up on the board by answering questions in various categories, which shuffle after each player's turn. In Beat the Teacher, contestants answer questions to win a turn to influence a tic-tac- toe grid.
  • 22. limitations  The game cannot be played by more than one players.  It is not a high level game.  It doesn’t contain levels. 7
  • 23. References  https://youtu.be/BHh654_7Cmw  Minimax Algorithm in Game Theory | Set 3 (Tic-Tac-Toe AI – Finding optimal move)- Geeks for Geeks https://www.geeksforgeeks.org/minimax-algorithm-in-game-theory-set-3- tic-tac-toe-ai-finding-optimal-move/  Tic Tac Toe AI with MiniMax using Python | Part 1: Programming Tic Tac Toe- YouTube https://www.youtube.com/watch?v=JC1QsLOXp-I  Tic Tac Toe AI with MiniMax using Python | Part 2: Minimax- YouTube https://www.youtube.com/watch?v=2Tr8LkyU78c 7