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
The cross-section of a rough, rectangular, concrete() channel measures . The channel slope is 0.02ft/ft. Using the Darcy-Weisbac
bazaltina [42]

Answer:

The following are the answer to this question:

Explanation:

In point a, Calculating the are of flow:

\bold{Area =B \times D_f}

         =6\times 5\\\\=30 \ ft^2

In point b, Calculating the wetter perimeter.

\bold{P_w =B+2\times D_f}

      = 6 +2\times (5)\\\\= 6 +10 \\\\=16 \ ft

In point c, Calculating the hydraulic radius:

\bold{R=\frac{A}{P_w}}

   =\frac{30}{16}\\\\= 1.875 \ ft

In point d, Calculating the value of Reynolds's number.

\bold{Re =\frac{4VR}{v}}

     =\frac{4V \times 1.875}{1 \times 10^{-5} \frac{ft^2}{s}}\\\\

     =750,000 V

Calculating the velocity:

V= \sqrt{\frac{8gRS}{f}}

   = \sqrt{\frac{8\times 32.2 \times 1.875 \times 0.02}{f}}\\\\=\frac{3.108}{\sqrt{f}}\\\\

\sqrt{f}=\frac{3.108}{V}\\\\

calculating the Cole-brook-White value:

\frac{1}{\sqrt{f}}= -2 \log (\frac{K}{12 R} +\frac{2.51}{R_e \sqrt{f}})\\\\ \frac{1}{\frac{3.108}{V}}= -2 \log (\frac{2 \times 10^{-2}}{12 \times 1.875} +\frac{2.51}{750,000V\sqrt{f}})\\

\frac{V}{3.108} =-2\log(8.88 \times 10^{-5} + \frac{3.346 \times 10^{-6}}{750,000(3.108)})

After calculating the value of V it will give:

V= 25.18 \ \frac{ft}{s^2}\\

In point a, Calculating the value of Froude:

F= \frac{V}{\sqrt{gD}}

= \frac{V}{\sqrt{g\frac{A}{\text{Width flow}}}}\\

= \frac{25.18}{\sqrt{32.2\frac{30}{6}}}\\\\= \frac{25.18}{\sqrt{32.2 \times 5}}\\\\= \frac{25.18}{\sqrt{161}}\\\\=  \frac{25.18}{12.68}\\\\= 1.98

The flow is supercritical because the amount of Froude is greater than 1.  

Calculating the channel flow rate.

Q= AV

   =30x 25.18\\\\= 755.4 \ \frac{ft^3}{s}\\

4 0
3 years ago
John has an exhaust leak in his Acura Integra GS-R, What steps would he take to fix the leak in time for his inspection?
SCORPION-xisa [38]

Answer:

Explanation:

Fist you need to identify where the leak is coming from. You can do this by either listening for the leak or spraying soapy water on the exhaust to look for air bubbles coming out of the exhaust. Depending on the spot of the leak there are many ways you can fix this leak.

1. Exhaust clamp

2. Exhaust putty

3. Exhaust tape

4. New exhaust

Exhaust clamp is best used for holes on straight pipes.

Putty is best used on welds or small holes like on exhaust manifolds or welds connecting various pieces like catalytic converters, mufflers, or resonators.

Tape will work best on straight pipes with holes.

New exhaust is for when the thig is beyond repair, like rust.

Now good luck because working on exhausts is a pain.

4 0
2 years ago
Which phrase best describes a safety-critical system? A. a system that faces a very high risk of failure B. a system isolated fr
KIM [24]

Answer:

B.

Explanation:

A safety-critical system (SCS) or life-critical system is a system whose failure or malfunction may result in one (or more) of the following outcomes: death or serious injury to people. loss or severe damage to equipment/property.

7 0
3 years ago
Which option identifies the concept represented in the following scenario?
dlinn [17]

Answer:

project object

Explanation:

3 0
3 years ago
Input Energy ---&gt; Output Energy
uranmaximum [27]

Answer:

motion ------> electrical. winds push the turbines which generate a magnetic fields which in turn, generates electricity

4 0
3 years ago
Other questions:
  • In a study comparing banks in Germany and Great Britain, a sample of 145 matched pairs of banks was formed. Each pair contained
    12·1 answer
  • A gear box’s shaft is made of a hollow circular steel tube with allowable yield stress equal to σa????????o???? . The shaft is l
    7·1 answer
  • tech a says that a tire with more wear on the center of the tread is caused by under inflation of the size tech b says featherin
    12·1 answer
  • Kjhwe ,kenwif ujwfeowlwfwfwfw...
    14·2 answers
  • A field sample of an unconfined aquifer is packed in a test cylinder. The length and diameter of the cylinder are 50 cm and 6 cm
    9·1 answer
  • A local surf report provides the height of the wave from the trough to the crest of the wave. How does this relate to the wave’s
    11·1 answer
  • Employees cannot be held legally responsible for an environmental violation.
    14·1 answer
  • Why charles babbage is known as father of computer explain <br>​
    12·1 answer
  • How many millimeters are there in a centimeter?
    10·1 answer
  • 11. As __and___ prices continued to rise in the late 1960’s and 70's, 4 and 6 cylinder engines began to make a comeback.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!