0% found this document useful (0 votes)
175 views16 pages

Tic Tac Toe

This document summarizes the key components of a Tic Tac Toe game program written in Python. The program uses a 3x3 grid to represent the game board and allows two players to take turns marking spaces with 'X' or 'O' with the goal of getting three in a row. It displays the board, gets player input, updates the board, checks for a winner or tie after each turn, and loops until the game ends. The code examples show how it prints the board, checks for a winner, initializes the board and game loop, handles player moves, and outputs the results of a win or tie.

Uploaded by

D JAYANTH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views16 pages

Tic Tac Toe

This document summarizes the key components of a Tic Tac Toe game program written in Python. The program uses a 3x3 grid to represent the game board and allows two players to take turns marking spaces with 'X' or 'O' with the goal of getting three in a row. It displays the board, gets player input, updates the board, checks for a winner or tie after each turn, and loops until the game ends. The code examples show how it prints the board, checks for a winner, initializes the board and game loop, handles player moves, and outputs the results of a win or tie.

Uploaded by

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

TIC TAC TOE

• A Tic Tac Toe game in Python is a program that emulates the classic two-
player board game. It provides a platform for players to take turns, marking
spaces on a 3x3 grid, with the goal of aligning three of their marks (either
'X' or 'O') horizontally, vertically, or diagonally. The program prompts users
to input their moves, validates the inputs to ensure they are within the valid
range and the chosen position is unoccupied, and then updates the game
board accordingly. The game continues until there is a winner or the board is
filled, resulting in a tie.
KEY COMPONENTS OF THE GAME….

• 1.Board Representation:
A 3x3 grid representing the Tic Tac Toe board, initialized with empty spaces.

• 2.Display Board:
A function to visually display the current state of the Tic Tac Toe board after each move.

• 3.Player Input:
Mechanism for two players to take turns and input their moves. Validation to ensure the input is a valid position
on the board and is not already occupied.

• 4.Update Board:
Logic to update the board based on the player's move, marking the chosen space with 'X' or 'O'.

• 5.Check Winner:
A function to check for a winner after each move, examining rows, columns, and diagonals for a winning alignment.

• 6.Game Loop:
A loop that continues until there is a winner or the board is filled, allowing players to take turns.
HOW TO PLAY TIC TAC TOE?

The game is played on a grid that's 3 squares by 3 squares

You are X , your friend (or the computer in this case) is O .


Players take turns putting their marks in empty squares.

The first player to get 3 of her marks in a row (up, down,


across, or diagonally) is the winner.

When all 9 squares are full, the game is over. If no player


has 3 marks in a row, the game ends in a tie.
OBJECTIVE AND KEY FEATURE OF THE GAME

OBJECTIVE:- • KEY FEATURE:-

To create a fun and


interactive game of To Create a user
tic tac toe friendly interface
To learn how to play and ace this fun python game
The “print_board” function displays the tic tac toe
board by printing each row with elements separated
by “|” and horizontal lines between rows. It provides
the visual state of the game

The “check_winner “function examines the tic


tac toe board if there is a winner .It checks for
matching symbols in row, columns. If winner is
identified it returns the winner symbol else it
returns “None”
This segment of the code checks for the winners in
both top-left-bottom and top-right-bottom
diagonals. So basically it just checks for the
winners in the diagonal's.

The is_board_full function checks for empty spaces


in the board. If there are any empty spaces it
returns False and if the board is full it returns True.
This segment of code initializes a 3*3 tic tac toe
board and sets “X” as starting player. Then it runs
an infinite loop prompting the user for a row and
column input until there is a winner.
This part of code deals with the player
moves in game. It checks if the chosen cell
is empty ,updates the board, checks for
winner or a tie, and toggles between “X”
and “O” for the next turn. If the selected
cell is already taken it prompts the user to
try again .
The game continues until there is a winner
or tie.
A GLANCE AT THE CODE
This output case 1 is where player “X” or “O”
wins
This output is case 2 is where it’s a
tie
EXPLANATION OF THE OUTPUT
• So, In the “play_tic_tac_toe” function, the game is played on a
3x3 board. Players take turns entering their moves as 'X' or 'O'
in the specified row and column. The game checks for a winner
after each move by calling the check_winner function. This is for
Case 1
• If the board is filled with 'X' and 'O' moves, but there is no
consecutive line of three identical symbols in any row, column, or
diagonal. The program then prints the final state of the board
and declares, "It's a tie!" This means that neither player was
able to achieve a winning combination, and the game concludes
with a draw.This is for case 2
Thank you 
Presented by D. Jayanth, Nihaldeep, Sai
Swaroop and Saunak

You might also like