Question
In C++ Connect-4 Game. A simple two player game, much like Tic-tac-toe.It is played on an 8 by 8 board. One player has X pieces
In C++
Connect-4 Game. A simple two player game, much like Tic-tac-toe.It is played on an 8 by 8 board. One player has X pieces and theother has O pieces. The players take turns, with X moving first.The goal is to make four in a row either horizontally, vertically,or diagonally. The program should support two human players or onehuman versus computer. It should reject illegal moves and it shoulddetect when the game ends (win or draw).
Please finish the game ”Connect4“ according to the existingcode.
****************************main.cpp***********************************
#include
#include "Connect4.h"
using namespace std;
int main(){
//testPlacePiece();
//testHorizontalWin();
return 0;
}
*******************************Connect4.h******************************
#ifndef CONNECT_4
#define CONNECT_4
/* this is the HEADER FILE declaring the class
you will implement in the .cpp file.
You may (and are encouraged to) add additional
private methods and instance variables as needed, but do not addany additional public methods.
Please use the constants in contexts where they
are appropriate.
*/
#include
const int ROWS = 8;
const int COLUMNS = 8;
const char PLAYER_ONE_PIECE = 'X';
const char PLAYER_TWO_PIECE = 'O';
const char EMPTY_SPACE = '-';
const int WIN_COUNT = 4;
enum Player { PLAYER_ONE, PLAYER_TWO };
class Connect4Board{
public:
Connect4Board();
// returns true if value ofcolumn is in-range
bool placePiece(int column, Playerplayer);
std::string boardToString();
bool isWin(Player player);
bool isDraw();
private:
// Add additional privatemethods and
// instance variables here asneeded
char board[ROWS][COLUMNS];
};
#endif
********************************Connect4.cpp******************************
#include "Connect4.h"
Connect4Board::Connect4Board(){
// YOUR CODE HERE
}
bool isColumnFull(int column){
// YOUR CODE HERE
}
bool Connect4Board::placePiece(int column, Player player){
// YOUR CODE HERE
}
std::string Connect4Board::boardToString(){
// YOUR CODE HERE
}
bool Connect4Board::isWin(Player player){
// YOUR CODE HERE
}
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