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]
3 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]3 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
Plant scientists would not do which of the following?
zavuch27 [327]

Explanation:

i think option 4 is correct answer because itsrelated to animal not plants.

6 0
3 years ago
Read 2 more answers
Which of the following types of protection is an employer required to pay for?
77julia77 [94]

Answer:

Hearing protection would be your answer!

Explanation:

This includes earplugs,muffs etc.

Hope it helps!

7 0
3 years ago
Read 2 more answers
The brakes are being bled on a passenger vehicle with a disc/drum brake system. Technician A says that the drums should be remov
exis [7]

The brakes are being bled on a passenger vehicle with a disc/drum brake system is described in the following

Explanation:

1.Risk: Continued operation at or below Rotor Minimum Thickness can lead to Brake system failure. As the rotor reaches its minimum thickness, the braking distance increases, sometimes up to 4 meters. A brake system is designed to take kinetic energy and transfer it into heat energy.

2.Since the piston needs to be pushed back into the caliper in order to fit over the new pads, I do open the bleeder screw when pushing the piston back in. This does help prevent debris from traveling back through the system and contaminating the ABS sensors

3.There are three methods of bleeding brakes: Vacuum pumping. Pressure pumping. Pump and hold.

4,Brake drag is caused by the brake pads or shoes not releasing completely when the brake pedal is released. ... A worn or corroded master cylinder bore causes excess pedal effort resulting in dragging brakes. Brake Lines and Hoses: There may be pressure trapped in the brake line or hose after the pedal has been released.

4 0
3 years ago
Patient people vote more often than non-patient people.<br> True<br> O<br> False
xxMikexx [17]

Answer:

True

Explanation:

8 0
2 years ago
What is the function of the rotor and the stator in an AC motor
sweet-ann [11.9K]
The rotor is situated inside the stator and is mounted on the AC motor's shaft. It is the rotating part of the AC motor. And while we know this, the major function of the rotor and the stator is helping the motor shaft rotate.
7 0
3 years ago
Other questions:
  • Which statement best describes how a hearing aid works?
    7·1 answer
  • Air is used as the working fluid in a simple ideal Brayton cycle that has a pressure ratio of 12, a compressor inlet temperature
    13·1 answer
  • 4.2 A vapor compression refrigeration machine uses 30kW of electric power to produce 50 tons of cooling. What is
    14·1 answer
  • Refrigerant-134a enters a diffuser steadily as saturated vapor at 600 kPa with a velocity of 160 m/s, and it leaves at 700 kPa a
    10·2 answers
  • Which of the following vehicles has no emissions?
    9·1 answer
  • A Coca Cola can with diameter 62 mm and wall thickness 300 um has an internal pressure of 100 kPa. Calculate the principal stres
    9·1 answer
  • W10L1-Show It: Pythagorean Theorem<br> Calculate the total material in the picture.<br> 4<br> 3
    14·1 answer
  • Which of the following is an example of a social need?
    5·1 answer
  • The resistance of a copper wire 200 m long is 21 Q. If its thickness (diameter) is 0.44 mm, its specific resistance is around___
    11·1 answer
  • What is the mode of operation of a ramp digital voltimeter​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!