1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mars1129 [50]
2 years ago
6

computer language C++ (Connect 4 game)( this is all the info that was givin no input or solution) I used the most recent version

of Microsoft visual studio for this program)Your solution must have these classes and at least these fields / methods. Your program must use the methods described in a meaningful fashion. You can create additional fields or methods but these the below should be core methods in your solution.Checkers classfields:colormethods:Constructorint getColor()string toString() - returns an attractive string representation of itselfBoard classfields:2D array of checkers - represents the game board (6 row by 7 column)methods:Constructorstring toString() - returns an attractive string representation of itselfThis needs to be an attractive table representation of the game board with aligned rows / columns with characters representing blank cells, cells with a red checkers in it and cells with a gold checkers in it.int dropChecker(Checker, int) - drops a checker object down a particular slot. Returns an int indicating success or not.int isWinner() - returns code number representing no winner or player number of winnerPlayer classfields:namecolormethods:Constructorget / set methods for fieldsstring toString() - string representation of itself.Example String representation of the board (X means blank, R means red checker, G means gold checker)X X X X X X XX X X X X X XX X X X X G XX X X X X R XX X X X X R XX R G G G R GMainYour program should create two Players and a Board. It should represent the initial Board to the screen.You should then alternate between player 1 and player 2 and randomly drop checkers down slots in the board. You should represent the board after each checker drop.This should stop if there is a winner or if the board fills up.You should be turning in a Checker.h, Checker.cpp, Board.h, Board.cpp, Player.h, Player.cpp and a main.cpp
Engineering
1 answer:
Mariana [72]2 years ago
4 0

Answer:

C++ code explained below

Explanation:

#include "hw6.h"

//---------------------------------------------------

// Constructor function

//---------------------------------------------------

Connect4::Connect4()

{

ClearBoard();

}

//---------------------------------------------------

// Destructor function

//---------------------------------------------------

Connect4::~Connect4()

{

// Intentionally empty

}

//---------------------------------------------------

// Clear the Connect4 board

//---------------------------------------------------

void Connect4::ClearBoard()

{

// Initialize Connect4 board

for (int c = 0; c < COLS; c++)

for (int r = 0; r < ROWS; r++)

board[r][c] = ' ';

// Initialize column counters

for (int c = 0; c < COLS; c++)

count[c] = 0;

}

//---------------------------------------------------

// Add player's piece to specified column in board

//---------------------------------------------------

bool Connect4::MakeMove(int col, char player)

{

// Error checking

if ((col < 0) || (col >= COLS) || (count[col] >= ROWS))

return false;

// Make move

int row = count[col];

board[row][col] = player;

count[col]++;

return true;

}

//---------------------------------------------------

// Check to see if player has won the game

//---------------------------------------------------

bool Connect4::CheckWin(char player)

{

// Loop over all starting positions

for (int c = 0; c < COLS; c++)

for (int r = 0; r < ROWS; r++)

if (board[r][c] == player)

{

// Check row

int count = 0;

for (int d = 0; d < WIN; d++)

if ((r+d < ROWS) &&

(board[r+d][c] == player)) count++;

if (count == WIN) return true;

 

// Check column

count = 0;

for (int d = 0; d < WIN; d++)

if ((c+d < COLS) &&

(board[r][c+d] == player)) count++;

if (count == WIN) return true;

 

// Check first diagonal

count = 0;

for (int d = 0; d < WIN; d++)

if ((r+d < ROWS) && (c+d < COLS) &&

(board[r+d][c+d] == player)) count++;

if (count == WIN) return true;

 

// Check second diagonal

count = 0;

for (int d = 0; d < WIN; d++)

if ((r-d >= 0) && (c+d < COLS) &&

(board[r-d][c+d] == player)) count++;

if (count == WIN) return true;

}

return false;

}

//---------------------------------------------------

// Print the Connect4 board

//---------------------------------------------------

void Connect4::PrintBoard()

{

// Print the Connect4 board

for (int r = ROWS-1; r >= 0; r--)

{

// Draw dashed line

cout << "+";

for (int c = 0; c < COLS; c++)

cout << "---+";

cout << "\n";

// Draw board contents

cout << "| ";

for (int c = 0; c < COLS; c++)

cout << board[r][c] << " | ";

cout << "\n";

}

// Draw dashed line

cout << "+";

for (int c = 0; c < COLS; c++)

cout << "---+";

cout << "\n";

// Draw column numbers

cout << " ";

for (int c = 0; c < COLS; c++)

cout << c << " ";

cout << "\n\n";

}

//---------------------------------------------------

// Main program to play Connect4 game

//---------------------------------------------------

int main()

{

  int choice;

  int counter = 0;

  srand (time(NULL));

  Connect4 board;

  cout << "Welcome to Connect 4!" << endl << "Your Pieces will be labeled 'H' for human. While the computer's will be labeled 'C'" << endl;

  board.PrintBoard();

  cout << "Where would you like to make your first move? (0-6)";

  cin >> choice;

  while (board.MakeMove(choice,'H') == false){

  cin >> choice;

  }

  counter++;

  while (board.CheckWin('C') == false && board.CheckWin('H') == false && counter != 21){

  while (board.MakeMove(rand() % 7, 'C') == false){}

  board.PrintBoard();

  cout << "Where would you like to make your next move?" << endl;

  cin >> choice;

  board.MakeMove(choice,'H');

  while (board.MakeMove(choice,'H') == false){

  cin >> choice;

  }

  counter++;

  }

 

  if (board.CheckWin('C')){

  cout << "Computer Wins!" << endl;}

  else if (counter == 21){cout << "Tie Game!" << endl;}

  else {cout << "Human Wins!" << endl;}

  board.PrintBoard();

}

You might be interested in
Turn the motor around in the circuit. What happens?
kenny6666 [7]

Answer:

It will create a massive drag and pretty much stop the motor.

Explanation:

7 0
3 years ago
If the same type of thermoplastic polymer is being tensile tested and the strain rate is increased, it will: g
Serggg [28]

Answer:

It would break I think need to try it out

Explanation:

3 0
2 years ago
Air flows through a 0.25-m-diameter duct. At the inlet the velocity is 300 m/s, and the stagnation temperature is 90°C. If the M
Naddika [18.5K]

Answer:

a. 318.2k

b. 45.2kj

Explanation:

Heat transfer rate to an object is equal to the thermal conductivity of the material the object is made from, multiplied by the surface area in contact, multiplied by the difference in temperature between the two objects, divided by the thickness of the material.

See attachment for detailed analysis

7 0
3 years ago
provides steady-state operating data for a solar power plant that operates on a Rankine cycle with Refrigerant 134a as its worki
Vaselesa [24]

Answer:

hello some parts of your question is missing attached below is the missing part ( the required fig and table )

answer : The solar collector surface area = 7133 m^2

Explanation:

Given data :

Rate of energy input to the collectors from solar radiation = 0.3 kW/m^2

percentage of solar power absorbed by refrigerant = 60%

Determine the solar collector surface area

The solar collector surface area = 7133 m^2

attached below is a detailed solution of the problem

8 0
3 years ago
C++A palindrome is a string such as "madam", "radar", "Dad", and "I", that reads the same forwards and backwards. The empty stri
jeka57 [31]

Answer:

See explaination

Explanation:

#include <iostream>

#include<string.h>

using namespace std;

bool isPalindrome(string str, int lower, int upper){

if(str.length() == 0 || lower>=upper){

return true;

}

else{

if(str.at(lower) == str.at(upper)){

return isPalindrome(str,lower+1,upper-1);

}

else{

return false;

}

}

}

int main(){

string input;

cout<<"Enter string: ";

cin>>input;

if(isPalindrome(input,0,input.length()-1)){

cout<<input<<" is a palindrome"<<endl;

}

else{

cout<<input<<" is NOT a palindrome"<<endl;

}

return 0;

}

5 0
2 years ago
Other questions:
  • A large part in a turbine-generator unit operates near room temperature and is made of ASTM A470-8 steel ( ). A surface crack ha
    11·1 answer
  • Determine the magnitude of the resultant force and the moment about the origin. Note: the symbol near the 140 N-m moment are not
    15·1 answer
  • A resonant six-turn loop of closely spaced turns is operating at 50 MHz. The radius of the loop is λ/30, and the loop is connect
    15·1 answer
  • A four-lane freeway (two lanes in each direction) is located on rolling terrain and has 12-ft lanes, no lateral obstructions wit
    14·1 answer
  • Tim was recently released from his last job. He was very rigid and would not change a product design once he began a project. He
    7·1 answer
  • A device that helps increase field worker productivity by providing reliable location and time
    13·1 answer
  • If you are convicted of D.U.I. a second time in five years, your license may be revoked for up to __________ year/s.
    10·1 answer
  • 7. What is the voltage across a 100 ohm circuit element that draws a current of 1 A?
    11·1 answer
  • Please I need help!<br><br> I need 1,2,&amp;3 drawn with front top and side view. Please help asap
    6·1 answer
  • Explain race condition..<br><br>don't spam..​
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!