Question
Finish Connect Four Board C++ program ( create the board, not the game ): Please use this header file: CFBoard.hpp enum gameState{ XWON, OWON, DRAW,
Finish Connect Four Board C++ program (create the board, not the game):
Please use this header file:
CFBoard.hpp
enum gameState{
XWON,
OWON,
DRAW,
UNFINISHED
};
class CFBoard{
private:
char array[7][6];
public:
Board();
bool makeMove(int x, int y, char ch);
gameState updateGameState();
void print();
};
Help me create a simple Connect Four C++ Game without structs.
Must use this answer as a template:
https://www.chegg.com/homework-help/questions-and-answers/note-write-one-line-discription-four-files-boardhpp-boardcpp-tictactoehpp-tictactoecpp-wri-q23489302
Please follow it. It should be just like the program above with a class and it shows how to display the board on the .cpp file.
The files must be named: CFBoard.hpp and CFBoard.cpp. Please use two files. No more than two or less.
Write a class called CFBoard as shown above that represents a game board for playing Connect Four.
Here are the complete program requirements (NOTE: I have already completed most of the .hpp class file above):
Here are the complete program requirements:
a 7x6 array of char as a data member, which will store the locations of the players' pieces.
a variable called gameState that holds one of the four following values: X_WON, O_WON, DRAW, or UNFINISHED - use an enum type for this, not string (the enum definition should go in CFBoard.hpp, before the class, not inside it).
a default constructor that initializes all elements of the array to being empty (you can use whatever character you want to represent that a square is empty).
a method called makeMove that takes the column of the move (1-7, see the example below) and which player's turn it is ('x' or 'o') as parameters. If the gameState is not UNFINISHED, or the selected column is already full, then makeMove should just return false. Otherwise, makeMove should record the move, call the updateGameState method (described next), and return true. The piece that is played should "fall" to the "lowest" unoccupied square of that column (see the example below).
a method called updateGameState. This method takes the array indices of the piece that was just played and updates the gameState if the game has now been won or drawn. The first parameter will be a row index (0-5) and the second parameter will be a column index (0-6). The game has been won when either player has four pieces in a row either orthogonally or diagonally. The game has been drawn when the board is completely full and neither player has won. Since this method is just for internal use, it would normally be private, but I want you to make it public so I can test it separately.
a method called getGameState that just returns the value of gameState.
A method called print, which just prints out the current board to the screen - this is not required, but will very likely be useful for debugging.
Here's a sample excerpt of a game in progress (it should look like this):
1 2 3 4 5 6 7
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . o . x . .
. x x o o . .
Next x plays in column 6:
1 2 3 4 5 6 7
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . o . x . .
. x x o o x .
Next o plays in column 5:
1 2 3 4 5 6 7
. . . . . . .
. . . . . . .
. . . . . . .
. . . . o . .
. . o . x . .
. x x o o x .
Whether you think of the array indices as being [row][column] or [column][row] doesn't matter as long as you're consistent. Also, whether the zero row is the "top" or "bottom" doesn't matter as long as you're consistent (same for "left" and "right").
The class only represents the board, it doesn't actually allow two players to play the game. Other code (that you don't have to write) would use your CFBoard class to make that happen.
Here are the program requirements:
a 7x6 array of char as a data member, which will store the locations of the players' pieces.
a variable called gameState that holds one of the four following values: X_WON, O_WON, DRAW, or UNFINISHED - use an enum type for this, not string (the enum definition should go in CFBoard.hpp, before the class, not inside it).
a default constructor that initializes all elements of the array to being empty (you can use whatever character you want to represent that a square is empty).
a method called makeMove that takes the column of the move (1-7, see the example below) and which player's turn it is ('x' or 'o') as parameters. If the gameState is not UNFINISHED, or the selected column is already full, then makeMove should just return false. Otherwise, makeMove should record the move, call the updateGameState method (described next), and return true. The piece that is played should "fall" to the "lowest" unoccupied square of that column (see the example below).
a method called updateGameState. This method takes the array indices of the piece that was just played and updates the gameState if the game has now been won or drawn. The first parameter will be a row index (0-5) and the second parameter will be a column index (0-6). The game has been won when either player has four pieces in a row either orthogonally or diagonally. The game has been drawn when the board is completely full and neither player has won. Since this method is just for internal use, it would normally be private, but I want you to make it public so I can test it separately.
a method called getGameState that just returns the value of gameState.
A method called print, which just prints out the current board to the screen - this is not required, but will very likely be useful for debugging.
Here's a sample excerpt of a game in progress (it should look like this):
1 2 3 4 5 6 7
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . o . x . .
. x x o o . .
Next x plays in column 6:
1 2 3 4 5 6 7
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . o . x . .
. x x o o x .
Next o plays in column 5:
1 2 3 4 5 6 7
. . . . . . .
. . . . . . .
. . . . . . .
. . . . o . .
. . o . x . .
. x x o o x .
Whether you think of the array indices as being [row][column] or [column][row] doesn't matter as long as you're consistent. Also, whether the zero row is the "top" or "bottom" doesn't matter as long as you're consistent (same for "left" and "right").
The class only represents the board, it doesn't actually allow two players to play the game. Other code (that you don't have to write) would use your CFBoard class to make that happen.
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