0% found this document useful (0 votes)
52 views5 pages

Python Project

This document outlines the functions and test cases for a Tic Tac Toe game implemented in Python. It includes 5 functions: create_board(), get_player_move(), get_computer_move(), check_win(), and play_game(). Each function is described and includes test cases to ensure correct functionality. A flowchart is also provided to illustrate the logic and flow of the game.
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)
52 views5 pages

Python Project

This document outlines the functions and test cases for a Tic Tac Toe game implemented in Python. It includes 5 functions: create_board(), get_player_move(), get_computer_move(), check_win(), and play_game(). Each function is described and includes test cases to ensure correct functionality. A flowchart is also provided to illustrate the logic and flow of the game.
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/ 5

Python Project

Project Activity
Group members:

• Vedant Trivedi

500096811

R252221099

• Aditya Somvanshi

500090886

R252221004

Topic: Tic Tac Toe implementation using five functions into another module by
Python

Function name Test Cases Functionality Design as Algorithm or


Description flowchart

• Test case for • Creates an


def create_board(): create_board empty board
function: for the game
• This function
Code: creates a new
board = create_board() game board
assert len(board) == 10 with an
assert board[0] == " " empty cell at
assert board[1] == " " index 0 and 9
assert board[9] == " " empty spaces
at indices 1-9.
• Test case for • Draws the Tic
def get_player_move(board): draw_board Tac Toe board
function: • This function
takes the
Code: game board
board = ["O", "X", "O", "X", as an
"O", "X", "O", "X", "O", "X"] argument and
draw_board(board) prints the
current state
of the board
to the
console.
• Test case for • Gets the
def get_computer_move(board): get_player_move player's move
function: and validates
Code: it
board = [" ", " ", " ", " ", " ", " • This function
", " ", " ", " ", " "] prompts the
assert player to
get_player_move(board) in enter a move
range(1, 10) (a number
between 1-9)
and returns
the move as
an integer.
• If the input is
not a number
or not
between 1-9,
the function
re-prompts
the player.
• If the cell
corresponding
to the input is
already taken,
the function
re-prompts
the player.
• Test case for • Generates the
def check_win(board, player): get_computer_move computer's
function: move

Code: • If the cell


board1 = ["X", "O", "X", " ", corresponding
"O", " ", "O", " ", "X", "O"] to the move is
board2 = ["X", "O", "X", " ", already taken,
"O", " ", "O", " ", "X", " "] the function
assert check_win(board1, generates a
"X") == True new move.
assert check_win(board2,
"X") == False
assert check_win(board1,
"O") == False
assert check_win(board2,
"O") == True
def play_game(): • Test case for • Checks if a
play_game function: player has
won the game
Code: play_game() • If the game is
still in progress,
the function
returns "not
over".

• The Code are as follows:

Here we are making a module named tic_tac_toe.py

Now, we are printing the tic_tac_toe.py into our module main.py


• Output:
• The Flowchart are as follows:

You might also like