Write a C++ program that plays the game of connect four. Connect Four has a 6 x
ID: 3764571 • Letter: W
Question
Write a C++ program that plays the game of connect four. Connect Four has a 6 x 7 board, and the goal of the game is to connect four pieces together horizontally, diagonally, or vertically. You need to make sure you handle inappropriate data, i.e. non-positive integers, and ask the user again for the correct input. You must continue to play the game, until the user no longer wants to play. A requirement for this program is that your functions are 10 lines or less, and you must not have any global variables. Write this code using arrays and strings
Example-
http://imgur.com/gallery/dkGS1rk/new
In addition to the 2-player game, you will need to support a 1-player game! If the user runs the program supplying a –a option, then you will run the game as 1-player connect four, where the other player is the computer. Print an error message and recover, when the player doesn’t supply a valid column on the board. This includes selecting a column that has filled all rows.
Print an error message when the user enters an invalid option as a command line argument. You do not need to recover from this.
Play the game correctly based on how many pieces to connect or when any user fails to win by the board completely filling. Continue to play until the user selects no.
Explanation / Answer
#include #include #include #define BOARD_ROWS 6 #define BOARD_COLS 7 void printBoard(char *board); int takeTurn(char *board, int player, const char*); int checkWin(char *board); int checkFour(char *board, int, int, int, int); int horizontalCheck(char *board); int verticalCheck(char *board); int diagonalCheck(char *board); int main(int argc, char *argv[]){ const char *PIECES = "XO"; char board[BOARD_ROWS * BOARD_COLS]; memset(board, ' ', BOARD_ROWS * BOARD_COLS); int turn, done = 0; for(turn = 0; turnRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.