Question
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.
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.
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.
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.
If you reach the end of the game and failed to win, it is a draw.
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started