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

Training and Development in Banking Sector

Tic-Tac-Toe is a two-player game played on a 3x3 grid where players aim to align three of their symbols in a row, column, or diagonal. The game is simple to learn and can end in a win or a draw, making it a popular pastime for all ages. The document details the game's rules, implementation in Python, and strategic elements involved in gameplay.

Uploaded by

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

Training and Development in Banking Sector

Tic-Tac-Toe is a two-player game played on a 3x3 grid where players aim to align three of their symbols in a row, column, or diagonal. The game is simple to learn and can end in a win or a draw, making it a popular pastime for all ages. The document details the game's rules, implementation in Python, and strategic elements involved in gameplay.

Uploaded by

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

TIC-TAC-TOE GAME

ABSTRACT

Tic-Tac-Toe is a two-player, zero-sum game played on a 3x3 grid, where players


alternately place either an "X" or an "O" in an empty square. The objective is to align
three of one's symbols in a row, column, or diagonal, before the opponent does. The
game is simple yet strategic, as players must think ahead to block their opponent’s
moves while creating opportunities for themselves. It is easy to learn, requiring no
special equipment, and can end either with a winner or in a draw if the grid is filled
without any player achieving a line of three. Despite its simplicity, Tic-Tac-Toe
serves as a foundational example of game theory and offers insights into basic
strategic thinking, making it a popular game for players of all ages.

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 1


TIC-TAC-TOE GAME

INTRODUCTION

Tic-Tac-Toe is a timeless and popular game that combines simplicity with strategy,
often played on a 3x3 grid. Each player takes turns placing either an "X" or an "O" in
an empty square, with the aim of being the first to form a line of three matching
symbols in a row, either horizontally, vertically, or diagonally. While the game’s
rules are straightforward, it offers a surprising depth of strategy as players anticipate
each other’s moves, try to block their opponent’s winning chances, and create
opportunities for themselves. If all squares are filled without a winner, the game ends
in a draw. Tic-Tac-Toe is enjoyed by people of all ages and can be a fun way to
challenge both friends and family, making it a great pastime that can be played
quickly and anywhere.

Tic-Tac-Toe is a classic two-player game played on a 3x3 grid where players take
turns marking a square with either an "X" or an "O". The objective is to align three of
your marks in a row, either horizontally, vertically, or diagonally, before your
opponent does. The game ends when one player achieves this goal, or when all the
squares are filled, resulting in a draw if no one wins. It’s a simple yet strategic game
that’s easy to learn and fun for players of all ages

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 2


TIC-TAC-TOE GAME

BRIEF DESCRIPTION

A two-player tic-tac-toe game, which we can play on the command line. Initially,
we'll make a blank game board and then we'll take inputs from the players and we'll
check for the winning situation if the entire board gets loaded and no one wins, we'll
declare the result as "tie" and ask users if they want to restart the game.

USED SOFTWARE /IDE

We will create this game using Python 3, so make sure you have it installed on your
laptop/computer and we are good to go.

HOW DOES THE GAME WORK

The board is numbered like the keyboard's number pad. And thus, a player can make
their action on the game board by entering the number from the keyboard number
pad.

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 3


TIC-TAC-TOE GAME

CODING

Utilize the dictionary to make our game board. A dictionary is a primitive data type in
python that kept data in "key: value" format. And thus, we'll make a dictionary of
length 9 and each key will illustrate a block on the board and its related value will
illustrate the move made by a player, and we'll make a function

PrintBoard ()

That we can utilize every time we want to print the updated board in the game.

Theboard = ('7': '', '8': '', '9': '',


'4':','5':'', '6:'".
''1'','2': '', '3': ''}

def. printBoardtboard);
print(board["7"]+-board[8] board[])
print('---
print(board[4]+"-board[5]-board['6'])
print()
print(hoand['1']+board['2']+bound['3'])

Now, in the main function, we'll first take the input from the player and review if the
input is a valid move or not. If the block that the player requests to move to is valid,
we'll fill that block else we'll ask the user to pick anothe blocked.

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 4


TIC-TAC-TOE GAME

def game():

turn=’x’
count=0

for i in range(10);
printBoard (the Board)
printf ("It's your turn." +turn +".Move to which place?")

move input()

if the Board[move]==’’;
the board [move] = turn

count+=1

else;
print("That place is already filled. \nMove to which place?")
continue

Now, to inspect the winning condition, we'll review a total of 8 conditions and
whichever player has made the last move, we'll declare that player a winner. And if no
one wins, we'll declare 'tie'.

# Now we will check if player X or O has won, for every move after 5 moves.

If count>= 5:

If theBoard['7'] theBoard['8'] theBoard['9'] !=: # across the top

printBoard(theBoard)

print("\nGame Over.\n")

print(" +turn+"won. *****")


A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 5
TIC-TAC-TOE GAME

break

elif the Board[4] theBoard['5'] the Board['6'] != # across the middle

printBoard(theBoard)

print("\nGame Over.\n")

print(" +turn "won. *******)

break

elif the Board[1] theBoard['2']theBoard['3'] != # across the bottom

printBoard(the Board)

print("\nGame Over. n")

print(****** +turn+won, wжет)

break

elif theBoard['1'] theBoard['4'] theBoard['7'] != #down the left side

printBoard(theBoard)

print("\nGame Over.\n")

print(" +turn"won)

break

elif theBoard['2'] theBoard['5'] theBoard['8'] # down the middle

printBoard(theBoard)

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 6


TIC-TAC-TOE GAME

print("\nGame Over.\n").

print(" +turn "won. ***)

break

elif the Board[3] theBoard['6'] theBoard['9'] != #down the right side

printBoard (theBoard)

print("\nGame Over.\n")

print("+turn + "won. ****")

break

elif the Board[7] the Board['5'] theBoard['3'] != # diagonal

printBoard(the Board)

print(nGame Over.\n")

print(***** +turn "won. ***)

break

elif the Board['1']theBoard[5] theBoard['9'] != #diagonal

printBoard(theBoard)

print(nGame Over.\n")

print(****** +turn "won. **88)

break

#If neither X nor O wins and the board is full, we'll declare the result as "tic'..
A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 7
TIC-TAC-TOE GAME

If count = 9;

Print("\nGame Over.\n")

Print("It's a Tie!!")

# we have to change the player after every move.


If turn =='X':

Turn = 'O'

Else:

Turn = 'X'

Adding code/ program to ask players to play again or not

Board keys = []

For key in theBoard:

Board_keys.append(key)

Restart = input("Do want to play Again?(y/n)")

If restart = "y" or restart = "Y":

For key in board keys:

theBoard[key] = ""

game()

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 8


TIC-TAC-TOE GAME

The tic-tac-toe game is ready to play full python code is given below.

#Implementation of Two Player Tic-Tac-Toe game in Python.

""We will make the board using dictionary


in which keys will be the location(ie: top-left, mid-right,etc.)
and initialliy it's values will be empty space and then after every move
we will change the value according to player's choice of move. ""

theBoard = ('7': '', '8': '', '9':'',


'4': '', '5':'', '6':'".
'1': '', '2': '', '3': ''}

board_keys = []

for key in theBoard:


board_keys.append(key)

""We will have to print the updated board after every move in the game and thus
we will make a function in which we'll define the printBoard function so that we
can easily print the board everytime by calling this function. ""

def printBoard(board):
print(board['7'] + ''+ board['8'] + '' + board['9'])
print('-+-+-')
print(board['4'] + '"' + board['5']+'' + board['6'])
print('-+-+-')
print(board['1'] + ''+ board['2'] + '' + board['3'])

# Now we'll write the main function which has all the gameplay functionality.
def game():

turn = 'X'
count = 0

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 9


TIC-TAC-TOE GAME

for i in range(10):
printBoard(theBoard)
print("It's your turn," + turn + ".Move to which place?")

move = input()

if theBoard[move] == '":
theBoard[move] = turn

count += 1

else:

print("That place is already filled.\nMove to which place?")

continue

# Now we will check if player X or O has won, for every move after 5 moves.

if count >= 5:

if theBoard['7'] == theBoard['8'] == theBoard['9'] != ''; # across the top


printBoard(theBoard)
print("\nGame Over.\n")
print("**** +turn + "won. ****")
break

elif theBoard['4'] == theBoard['5'] == theBoard['6'] != '': # across the middle


printBoard(theBoard)
print("\nGame Over.\n")
print("**** +turn + "won. ****")
break

elif theBoard['1'] == theBoard['2'] == theBoard['3'] != '': # across the bottom


printBoard(theBoard)
print("\nGame Over.\n")
print("**** +turn +" won. ****")
A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 10
TIC-TAC-TOE GAME

break

elif the Board['1'] == theBoard['4'] == theBoard['7'] != '': # down the left side
printBoard(theBoard)
print("\nGame Over.\n")
print(" ****"+turn + "won. ****")
break

elif theBoard['2'] == theBoard['5'] == theBoard['8'] != '': # down the middle


printBoard(theBoard)
print("\nGame Over.\n")
print("**** +turn + "won. ****")
break

elif theBoard['3'] == theBoard['6'] == theBoard['9'] != '': #down the right side


printBoard(theBoard)
print("\nGame Over.\n")
print("****+turn + "won. ****")
break

elif theBoard['7'] == theBoard['5'] == theBoard['3'] != '': # diagonal


printBoard(theBoard)
print("\nGame Over.\n")
print("**** +turn +" won. ****")
break

elif theBoard['1'] == theBoard['5'] == theBoard['9'] != '': # diagonal


printBoard(theBoard)
print("\nGame Over.\n")
print("****"+turn + "won. ****")
break

# If neither X nor O wins and the board is full, we'll declare the result as 'tie'.
if count == 9:
print("\nGame Over.\n")
print("It's a Tie!!")

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 11


TIC-TAC-TOE GAME

# Now we have to change the player after every move.


if turn =='X':
turn = '0'
else:
turn = 'X'

# Now we will ask if player wants to restart the game or not.


restart = input("Do want to play Again?(y/n)")
if restart == "y" or restart == "Y":
for key in board_keys:
theBoard[key] =””

game()
if_name_==”_main_”:
game()

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 12


TIC-TAC-TOE GAME

OUTPUT

The output of the above python program the game is working and a working
screenshot of this game is given below.

After creating this game, we can get a pretty exact idea about dictionaries in python,
how to access dictionaries, how to iterate over dictionaries, for loop, if-else conditions,
and functions in python.

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 13


TIC-TAC-TOE GAME

CONCLUSION

A two-player tic-tac-toe game, which we can play on the command line. Python is
generally utilized for creating websites and software, task automation, data analysis,
and data visualization.

In a Tic Tac Toe game, the conclusion occurs when either one player achieves three of
their marks in a row, column, or diagonal, resulting in a win for that player, or when
the board fills up with no winner, leading to a draw. If Player X or Player O manages
to align their marks successfully, the game ends with a declaration of their victory. If
all nine squares are filled without anyone winning, the game concludes as a tie. This
simple structure makes for a quick and engaging game, often played multiple times to
determine a series winner.

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 14


TIC-TAC-TOE GAME

 REFERENCES

1) Third year PWP book


2) Figures are download from www.msbte.com
3) www.google.com
4) www.geeksforgeeks.com
5) www.scribd.com
6) For type this project we have use a MS-word

A.C.S.’S. DIPLOMA IN ENGG & TECH, ASHTI Page | 15


TIC-TAC-TOE
GAME

17

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy