Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a C++ program to check a tic-tac-toe game and show its winning result in detail. This is an application program of a 3-dimensional

Please write a C++ program to check a tic-tac-toe game and show its winning result in detail. This is an application program of a 3-dimensional list or array.

Your complete test run output must look as follows. This test really checks to make sure your program is performing perfectly to check every possible winning situation for X and O.

Welcome to the TicTacToe program by "you"!

GAME 0 is as follows:

OOO

OOO

OOO

O won by row 1

O won by row 2

O won by row 3

O won by column 1

O won by column 2

O won by column 3

O won by diagonal 1

O won by diagonal 2

GAME 1 is as follows:

XXX

XXX

XXX

X won by row 1

X won by row 2

X won by row 3

X won by column 1

X won by column 2

X won by column 3

X won by diagonal 1

X won by diagonal 2

GAME 2 is as follows:

XOX

XXO

XOO

X won by column 1

X won by diagonal 2

GAME 3 is as follows:

XOO

OXO

XXO

O won by column 3

GAME 4 is as follows:

XOX

OXO

XOO

X won by diagonal 2

GAME 5 is as follows:

OXO

XOX

XOX

It is a tie.

Please enter your game board (* to exit)>OOOXOXOXO

Your game board is as follows:

OOO

XOX

OXO

O won by row 1

O won by diagonal 1

O won by diagonal 2

Please enter your game board (* to exit)>OXOOXOOXO

Your game board is as follows:

OXO

OXO

OXO

O won by column 1

X won by column 2

O won by column 3

Please enter your game board (* to exit)>XOXXXXOXO

Your game board is as follows:

XOX

XXX

OXO

X won by row 2

Please enter your game board (* to exit)>*

Thank you for playing this game designed by "you"

Your main program must have the following code to set up the preset 6 games.

# MAIN PROGRAM: ================================================.

print ("Welcome to the TicTacToe program designed by "you")

O = 'O' # player O

X = 'X' # player X

tlist = [ [ [O,O,O], # Game 0 # tlist is like a 3-dimensional array.

[O,O,O],

[O,O,O] ] ,

[ [X,X,X], # Game 1

[X,X,X],

[X,X,X] ] ,

[ [X,O,X], # Game 2

[X,X,O],

[X,O,O] ] ,

[ [X,O,O], # Game 3

[O,X,O],

[X,X,O] ] ,

[ [X,O,X], # Game 4

[O,X,O],

[X,O,O] ] ,

[ [O,X,O], # Game 5 # It is a tie.

[X,O,X],

[X,O,X] ] ]

for i in range(6): # 6 games to check one by one

print("GAME", i ," is as follows:")

show( tlist[i] )

checkwin( tlist[i] )

# More code to keep getting input from the user for the next game

# Stop this program if users input is *

# Thank the user before exit

# End of Program ########################################

You must define show( ) function to show the 3X3 game board.

You must define checkwin( ) function to check all the winning situations for X and O.

You must define 8 functions to check 8 possibilities to win:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions