Question: In this lab you will write a that will let two players play the game of Tic Tac Toe. You will write functions to perform
In this lab you will write a that will let two players play the game of Tic Tac Toe. You will write
functions to perform various sub tasks checking rows, checking column, checking diagonal,
checking for empty cells, and printing grid Grid will be represented with a nested D list.
Outer list will contain three inner list each representing a row of the grid Each inner grid will
contain three elements one for each column Elements of the inner list can be an xo or
blank Make sure that you read this lab handout carefully before starting to write your code.
You will implement the following functions:
resetgrid grid: reset the grid by changing all the elements to blank
checkrow grid rownum: returns True if all the elements in the given row are x or all
the elements in the given row are o otherwise it will return False.
checkcolumn grid colnum: returns True if all the elements in the given column are x
or all the elements in the given column are o otherwise it will return False.
CSCI Lab Page of
checkdiagonal grid diagonal: returns True if all the elements in the given diagonal are
x or all the elements in the diagonal are o otherwise it will return False. Note that the
diagonal d includes elements and and the diagonal d includes
elements and
placeentry grid rownum, colnum, ch: places the ch into the location given by
rownum and colnum ch will be either x or o It will check to make sure that the cell
given by rownum and colnum is blank. If it is blank then it will place the ch in the
given location and return True. If the cell is not empty then it will return False.
playable grid: check to see if there are any empty blank elements. It will use nested
loops to check each element in the nested list. If any of the element is empty blank then
it will return True, otherwise it will return False.
printgrid grid: prints grid using f string.
main function will use the above set of functions to perform various task. Outline of the main
function is as follows:
Create a nested lists as follows:
grid
Ask player to enter their name. Player will get x and will go first.
Ask player to enter their name. Player will get o and will go second.
Loop which iterates till game is over. Game will end when one of the players wins or
there are no more empty cells in the grid.
a Ask player one to enter the location which they want to mark the location. The player
will enter two integers as x y; where x is the row number and y is the column number.
Example: Note that players will count rows and columns as and but our
program will use and for row number and column number.
i Check to make sure that the entered row number and column numbers are or
If they are not then print an error message and player loses their turn.
ii Use the placeentery function to place an x in the selected location. If placeentry
returns a False then print an error message and player loses their turn.
iii. Print the grid.
iv Use checkrow function to check the selected row for completion. If the
checkrow function returns True then print the message that Player won the
game and this will end the game.
v Use checkcolum function to check the selected column for completion. If the
checkrow function returns True then print the message that Player won the
game and this will end the game.
vi If the player placed the mark on the diagonal d or d the use the
checkdiagonal function to check for completion. If the checkdiagonal function
returns True then print the message that Player won the game and this will end
the game.
vii. Use playable function to check if there are any empty cells. If playable function
returns False then there are no empty cells. Print the message that game is draw
and end the game.
CSCI Lab Page of
b Ask player two to enter the location which they want to mark the location. The player
will enter two integers as x y; where x is the row number and y is the column number.
Example: Note that players will count rows and columns as and but our
program will use and for row number and column number.
i Check to make sure that the entered row number and column numbers are or
If they are not then print an error message and player loses their turn.
ii Use the placeentery function to place an o in the selected location. If placeentry
returns a False then print an error message and player loses their turn.
iii. Print the grid.
iv Use checkrow function to check the selected row for completion. If the
checkrow function returns True then print the message that Player won the
game and this will end the game.
v Use checkcolum function to check the selected column for compl
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
