Using C++ language I need a program that plays the game of Connect Four. I need only 2 player mode: where the code will first display the empty board, below, I will publish what the board should look like and the code for it, then prompt the first player to select a column.
After a column is selected, it has to output a new, updated board with the player's piece at the bottom of the selected column. Then, player two can then choose a column in which to drop their piece. This behavior continues (alternating between players) until a winner is determined or until no more pieces can be dropped into the board (resulting in a tie).
PLEASE make sure to use 2D dynamic array to represent the game board. There shouldnt be memory leaks, make sure to delete everything and free the memory. Make sure you are creating the 2d-array for your board properly. Because otherwise the given board code (at the very end) will be trying to access memory that has not been allocated.
You are also asked to use int argc, char** argv[] or char* argv[] to pass the arguments into the function. For example, to start a program execution with a board that has 8 rows and 5 columns you will need to do ./main 8 5 before launching the program. Notice, that the board shouldn't have more than 20 rows and columns.
Please also make sure to do error handling for the column input, for example if user wants to put his piece into column 9 and there are only 6 columns then your program should print an error message and reprompt the user. The input should always be an integer, make sure to do error handling for it as well. Also think about the situation when column that is already full of pieces, user should be reprompted once again. Please try to make all the functions no more than 15 lines inside the curly braces of any function, including main(). It is not obligatory but very important. You must not use global variables!
Finally, your program should be able to detect the winner immediately if there are 4 adjacent X or O pieces horizontally, vertically, or diagonally and then print the winners name. If there is no winner then a tie message should be printed. At the very end the program asks users if they want to run it again, and runs it again if answer is 1.
Here I attached how the code that creates the board should look like:
here is an example of what the output should look like:
Overall, please get acquainted with all the requirements and fulfill them. I would definitely upvoat a good code. Thanks.