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
How many grams of perchloric acid, HClO4, are contained in 37.6 g of 70.5 wt% aqueous perchloric acid? How many grams of water a
kap26 [50]

Answer :

The mass of perchloric acid is, 26.5 grams.

The mass of water in the same solution is, 11.1 grams

Explanation :

As we are given that 70.5 wt % aqueous perchloric acid that means 70.5 grams of perchloric acid present in 100 grams of solution.

Now we have to determine the mass of perchloric acid in 37.6 grams of aqueous perchloric acid.

As, 100 grams of aqueous perchloric acid (solution) contains 70.5 grams of perchloric acid.

So, 37.6 grams of aqueous perchloric acid (solution) contains \frac{37.6}{100}\times 70.5=26.5 grams of perchloric acid.

Thus, the mass of perchloric acid is, 26.5 grams.

Now we have to determine the mass of water are in the same solution.

Total mass of solution = 37.6 g

Mass of perchloric acid = 26.5 g

Mass of water = Total mass of solution - Mass of perchloric acid

Mass of water = 37.6 g - 26.5 g

Mass of water = 11.1 g

Thus, the mass of water in the same solution is, 11.1 grams

4 0
3 years ago
Two routes connect an origin and a destination. Routes 1 and 2 have performance functions t1 = 2 + X1 and t2 = 1 + X2, where the
Musya8 [376]

Solution :

Given

$t_1=2+x_1$

$t_2=1+x_2$

Now,

$P(h

$0.4=1-P(h \geq5)$

$0.6=P(h \geq5)$

$0.6= e^{\frac{-x_1 5}{3600}}$

Therefore,   $x_1=368 \ veh/h$

                        $=\frac{368}{1000} = 0.368$

Given,   $t_1=2+x_1$

                 = 2 + 0.368

                 = 2.368 min

At user equilibrium, $t_2=t_1$

∴  $t_2$ = 2.368 min

$t_2=1+x_2$

$2.368=1+x_2$

$x_2 = 1.368$

$x_2 = 1.368 \times 1000$

    = 1368 veh/h

7 0
3 years ago
Two technicians are discussing the intake air temperature (IAT) sensor. Technician A says that the computer uses the IAT sensor
mart [117]

Both the technicians are correct.

Explanation

Intake air temperature sensor is used in engines of vehicles to monitor the temperature of air entering the engine.

They are basically made of thermistors whose electrical resistance changes according to temperature.

Depending upon the reading and accuracy of intake air temperature sensor, the power-train control module (PCM) will decide about the air and fuel mixture ratio in the engine.

The hot air in engine requires less fuel to operate the engine parts while cold air requires more fuel to operate the engine.

The ratio of air and fuel mixture should be maintained in the engine and it is done by PCM only after getting the input from IAT. So technician B is saying correct.

Also the IAT works as a backup to support the engine coolant temperature sensor by the computer.

As the IAT checks the temperature of outside air, it will help to change the coolant temperature of the engine based on the environment.

Thus technician A is also correct. So both the technicians are correct.

6 0
3 years ago
Water flows through a horizontal plastic pipe with a diameter of 0.15 m at a velocity of 15 cm/s. Determine the pressure drop pe
Sonja [21]

Answer:0.1898 Pa/m

Explanation:

Given data

Diameter of Pipe\left ( D\right )=0.15m

Velocity of water in pipe\left ( V\right )=15cm/s

We know viscosity of water is\left (\mu\right )=8.90\times10^{-4}pa-s

Pressure drop is given by hagen poiseuille equation

\Delta P=\frac{128\mu \L Q}{\pi D^4}

We have asked pressure Drop per unit length i.e.

\frac{\Delta P}{L} =\frac{128\mu \ Q}{\pi D^4}

Substituting Values

\frac{\Delta P}{L}=\frac{128\times8.90\times10^{-4}\times\pi \times\left ( 0.15^{3}\right )}{\pi\times 4 \times\left ( 0.15^{2}\right )}

\frac{\Delta P}{L}=0.1898 Pa/m

4 0
3 years ago
A cylindrical insulation for a steam pipe has an inside radius rt = 6 cm, outside radius r0 = 8 cm, and a thermal conductivity k
goldfiish [28.3K]

Answer:

heat loss per 1-m length of this insulation is 4368.145 W

Explanation:

given data

inside radius r1 = 6 cm

outside radius r2 = 8 cm

thermal conductivity k = 0.5 W/m°C

inside temperature t1 = 430°C

outside temperature t2 = 30°C

to find out

Determine the heat loss per 1-m length of this insulation

solution

we know thermal resistance formula for cylinder that is express as

Rth = \frac{ln\frac{r2}{r1}}{2 \pi *k * L}   .................1

here r1 is inside radius and r2 is outside radius L is length and k is thermal conductivity

so

heat loss is change in temperature divide thermal resistance

Q = \frac{t1- t2}{\frac{ln\frac{r2}{r1}}{2 \pi *k * L}}

Q = \frac{(430-30)*(2 \pi * 0.5 * 1}{ln\frac{8}{6} }

Q = 4368.145 W

so heat loss per 1-m length of this insulation is 4368.145 W

4 0
3 years ago
Other questions:
  • In what situation you would prefer to use a successive approximation ADC over flash ADC?
    13·1 answer
  • Let suppose, you are going to develop a web-application for school management system. Then what architectural pattern will you u
    9·1 answer
  • Nicholas wants to verify whether a file is a hard link to a file within the same directory. Which of the following commands coul
    6·1 answer
  • Sketch the velocity profile for laminar and turbulent flow.
    15·1 answer
  • What is the advantage of Sensabot over human inspectors?
    12·1 answer
  • A designer needs to select the material for a plate under tensile stress. Assuming that the applied tensile force is 13,000 lb a
    5·1 answer
  • Sarah and Raj take/takes me to a baseball game every year.
    11·1 answer
  • Engineering problems and it solutions it machine design​
    5·1 answer
  • What is the creative process that helps you overcome writer's block called?
    13·1 answer
  • Which step in the engineering design process does not come before building a<br> prototype?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!