Question
C++ help! Beginner pogramming, nothing crazy complicated please! No global varibles! Write a class called CFBoard that represents a game board for playing Connect Four
C++ help! Beginner pogramming, nothing crazy complicated please! No global varibles! Write a class called CFBoard that represents a game board for playing Connect Four (Links to an external site.)Links to an external site.. It should have: 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) and initializes the gameState to UNFINISHED. 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. optional: 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:
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 .
Et cetera. 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"). Your 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 Board class to make that happen. The files must be named: CFBoard.hpp and CFBoard.cpp.
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