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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!