Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Help please!!!!! Please do not use global variables and please nothing to fancy as Im a super beginner. Thanks! Write a class called CFBoard

C++ Help please!!!!! Please do not use global variables and please nothing to fancy as Im a super beginner. Thanks!

Write a class called CFBoard that represents a game board for playing Connect Four.

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.

Please make sure everything is followed on the prompt above.

PLEASE HELP!!!!!!!!!!!!!

Thank you very muhc!!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions

Question

1. How will you, as city manager, handle these requests?

Answered: 1 week ago