Question
write codes in python Connect Four is a two-player game in which the players first choose a color and then take turns dropping one colored
write codes in python
Connect Four is a two-player game in which the players first choose a color and then take turns dropping one colored disc from the top into N-column, N-row vertically suspended grid. The discs fall straight down, occupying the lowest available space within the column (refer to Figure 1). The objective of the game is to be first to form a horizontal, vertical, or diagonal line of four of ones discs.
To model the grid, we use a n*n two dimensional array. Initially, each cell of the grid is set to -1 (empty). The cell is set to 1 (respectively 2) if it contains player1s disc (respectively player2s disc).
Part I
-
Initialization
Write a function or a procedure to initialize a n*n grid.
-
Display
At each round, the current state of the grid will be displayed. Write a procedure to display the a given grid assuming the following notation: dics of player 1 are represented by X while the ones of player 2 are represented by O.
-
Play
Write a function or a procedure that allows a given player to play. Note that in the case in which the player chooses a column that is already full or a column out of range, an error message should be displayed. If there are no errors the function returns 0. Otherwise, it returns -1.
-
Winner
At the end of each round, the program needs to check if there is a winner. Write a function that returns either the winner number (if any) or 0.
-
Turn
Write a function that makes the players play in turn until the end of the game. Note that, in case of errors, the player is asked to play again. In addition, at each round, the state of the current grid is displayed at at the end the winner is highlighted.
Part II
In this part we allow each player to do an additional action at each round: rotate the grid by 90 in the clockwise direction.
We assume that the user chooses the number of rotations he wants to perform at each round. The rotation is only done at the end of each tour.
-
Write the functions/procedures needed to implement this new version of the game.
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