Connect Four is a two player game played on a grid. In turns, each player places a chip on the lowest available cell in a column. The game continues until one player manages to get 4 of chips in a line (horizontal, vertical, or diagonal), or until the grid is filled. At the start your program should print an empty 5 x 6 grid, empty fields are represented with 'O'. When printing the grid print a white space between each character in columns. After you print the grid, you should ask Player 1 to input an integer that represents the column number where e place where Player 1 put a chip. Note that the chip is going to be placed in the last row of the selected column unless there are more chips in that column, then it is going to be placed in first empty row from the bottom-up. Next, Player 2 picks a column in the same way as previously described, and a new grid is printed with 'Y' in their selected place.
Notes:
Figure: see image.
You are required to have at least 2 functions for this part, whose headers are as follows.
int update_game_board(char player, int chip_column, char grid[][6])
Takes as input a char representing the player, the column number given by the user, and 2D character array game board. This function then updates the board by placing the chip on the specified column if it is a valid column and the column is not full. The function returns the row number where the new chip was placed if the update was successful. Otherwise, return-1 if the column is full; and returns-2 if the specified column is not valid.
int check_winner (int chip_column, int chip_row, char grid[][6])
Takes as input a position (row and column) of the newly placed chip and the updated grid. The function then checks if that player has 4 chips in line, and it returns 1 if that is true and otherwise.
Let's Play Connect Four!
Grid:
O O O O O O
O O O O O O
O O O O O O
O O O O O O
O O O O O O
Play 1, pick a column: 4
Grid:
O O O O O O
O O O O O O
O O O O O O
O O O O O O
O O O O R O
Play 2, pick a column: 2
Grid:
O O O O O O
O O O O O O
O O O O O O
O O O O O O
O O YO RO
Play 1, pick a column: 4
Grid:
O O O O O O
O O O O O O
O O O O O O
O O O O R O
O O Y O R O
Play 2, pick a column:
.
.
.
Grid:
O O O O O O
O O O O O O
O O O O R O
O O Y O R O
O O Y Y R O
Play 1, pick a column: 4
Grid:
O O O O O O
O O O O R O
O O O O R O
O O Y O R O
O O Y Y B O
Player 1 wins!!!
There are 3 outcomes to the game.
1. If player 1 wins, print: "Player 1 wins!!!"
2. If player 2 wins, print: "Player 2 wins!!!"
3. If there is no winner, print: "It is a tie"
Error checking:
You have to perform some error checks while the game is being played. However, these errors will not cause the program to terminate. Furthermore, if the player enters something erroneous, it will ask that player to enter a new integer. The specific errors you are required to test for, and the corresponding messages, are as follows: (note that no other errors need to be checked)
ERROR: Illegal column #
ERROR: No more space in column #