Python Microproject Gro
Python Microproject Gro
AKOLA
Semester VI
Submitted By
1
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
CERTIFICATE
2
INDEX
Sr. Topic page
NO No
1 4
Introduction To
Tic-Tac-Toe
Game
2 5
Abstract
3 Rationale 6
4 6
Aim of the project
6 Program code 7
7 Output 11
8 Skill Developed 13
10 Refernces 14
3
Introduction To Tic-Tac-Toe
Game
Tic tac toe Python, also known as Noughts and Crosses or Xs and Os, is
a very simple two-player game where both the player get to choose any of the
symbols between X and O. This game is played on a 3X3 grid board and one by
one each player gets a chance to mark its respective symbol on the empty
spaces of the grid.
In the tic tac toe Python game that we shall be building, we require two
players. These two players will be selecting their respective two signs which
are generally used in the game that is, X and O. The two players draw
the X and O on an alternative basis on the 3x3 grid having 9 empty boxes.
4
Abstract
5
1.0 Rationale
The objective of this project is to develop the well-known
board game Tic-Tac- Toe for two players.
Generally, this is a two-player strategy board game. The Tic-
Tac-Toe game is based on having a game board (2D array) of size 3 x
3. The players alternate placing Xs and Os on the board until either
one has placed three Xs or Os in a row horizontally, vertically, or
diagonally; or all nine board squares are filled. The player wins if
s/he draws three Xs or three Os in a row. Otherwise, the game is
draw.
Initially the board grid squares are initialized to zeros. Xs and
Os might be denoted by numbers inside the board grid by ones and
twos respectively. I.e. if player one chooses X, the location of that
choice is registered as 1 and when player two chooses O the location
of that choice in your array is registered as 2. At the end if a row of 1s
is registered then player one won the game. Or if a row of 2s is
registered thus player two won the game. If not, the game is draw.
The game ends when there is no more empty fields in the array
(board) to fill or if one of the players wins the game.
6
4. Develop functions for given problems.
Program code
Python. theBoard = {'1': ' ' , '2': ' ' , '3': ' ' ,
'4': ' ' , '5': ' ' , '6': ' ' ,
'7': ' ' , '8': ' ' , '9': ' ' }
board_keys = []
def printBoard(board):
print("\n")
print(' '+board['1'] + ' | ' + board['2'] + ' | ' +
board['3']) print(' ---+---+---')
print(' '+board['4'] + ' | ' + board['5'] + ' | ' +
board['6']) print(' ---+---+---')
print(' '+board['7'] + ' | ' + board['8'] + ' | ' +
board['9']) print("\n")
# Now we'll write the main function which has all the gameplay
functionality. def game():
turn = 'X'
count = 0
for i in range(10):
printBoard(theBoard)
7
move=input("It's your turn," + turn + ". Move to which
8
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
break
elif theBoard['8'] == theBoard['5'] == theBoard['2'] != ' ': # down the
middle printBoard(theBoard)
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
break
elif theBoard['9'] == theBoard['6'] == theBoard['3'] != ' ': # down the right side
printBoard(theBoard)
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
break
elif theBoard['1'] == theBoard['5'] == theBoard['9'] != ' ': #
diagonal printBoard(theBoard)
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
break
elif theBoard['7'] == theBoard['5'] == theBoard['3'] != ' ': #
diagonal printBoard(theBoard)
print("\nGAME OVER.\n\n")
print(" ****** CONGRATULATIONS! " +turn + " YOU WON THE GAME
******\n\n")
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\n")
print("*** IT'S A TIE!!
***\n\n")
break
9
# Now we have to change the player after
every move. if turn =='X':
turn = 'O'
else:
turn = 'X'
10
Output:-
11
12
Skill Developed/ learning out of this Micro-Project We learnt,
1. Thisproject can be used as an interesting game for children to pass their free
time.
2. The project can be also used to understand the.
3. The project can be used in learning the
13
References :-
i.
14