Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python create a program for two players to play Noughts and crosses. The game begins by displaying on the screen the game board, which

In python

create a program for two players to play Noughts and crosses.

The game begins by displaying on the screen the game board, which will contain 9 positions and asking which turn will be the first, X or Y.

image text in transcribed

Initially all the boxes are empty and the first turn must choose a line and a column. If it was a valid and unoccupied line and column, follow the other player.

image text in transcribed

If the line or column is out of range, the variable that has been out of range must be requested again as many times as necessary.

image text in transcribed

After each line or column, each column, line and diagonal must be checked to see if the game is won with that position, otherwise follow the next turn.

image text in transcribed

If you reach the end of the game and failed to win, it is a draw.

image text in transcribed

Notes on the development of the program: You need to properly structure your program using functions. At least you must have two functions. I recommend that you have a main (), a function that prints the board and another to validate the board (if there are columns, lines or diagonals) If you are asked to put an X or O in a position that is already occupied the game should not allow it, you must ask for other coordinates. You can use different characters than those specified to design your game. When displaying the table, use formats so that all X and O are shown with the same amount of spaces and are aligned. The program must validate all the data requested by the user; that is to say: That the line and column number exist. Do not ask to occupy the same box that is already occupied Suggestion to generate the initial board: Use a for cycle to generate the 3 x 3 board You do not have to use a matrix, you can use a dictionary where instead of asking for lines and columns, you use positions from 1 to 9, and the value of the positions (which will be the keys) will be the X or Y. Do a function to print the board Use a cycle to change shifts, I suggest you have a shift variable, which changes in each cycle, from X to O or from O to X. In each cycle, call the function that prints the board. In each turn, ask for the line and the column, validate them and if they are valid, place the X or O in its place and check if with that play you won the game or not. If not, continue playing, if you already won, finish the cycle.

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

Building The Data Warehouse

Authors: W. H. Inmon

4th Edition

0764599445, 978-0764599446

More Books

Students also viewed these Databases questions

Question

Develop successful mentoring programs. page 400

Answered: 1 week ago