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
Early American rockets used an RC circuit to set the time for the rocket to begin re-entry after launch (true story). Assume the
koban [17]

Answer:

C = 0.3 F

Explanation:

The expression for a voltage in a capacitor with an initial voltage V₀, as a function of time, is given by the following equation:

V= Vo*e^{-t/RC}

When V = =.37*V₀, we have the following expression:

\frac{V}{Vo} = e^{-t/RC} = 0.37

Applying ln to both sides, we have:

\frac{-t}{RC} = ln 0.37 = -1

⇒ t = R*C

if t= 300 s, and R = 10³ Ω, we can solve for C as follows:

C = \frac{t}{R} = \frac{3e2 s}{1e3 ohms} = 0.3 F

So, the required value for C is 0.3 F.

3 0
3 years ago
What is the zone that has just been added to the exchange zone where athletes may now hand off the baton
Vanyuwa [196]

Answer:

The zone where athletes may hand off baton in exchange zone is the changeover zone.

Explanation:

A relay race is a track event that involves the exchange of baton among a set of athletes. The baton is majorly exchange within the exchange zone which is 20 meters long. The exchange zone is made up on two other zones:  acceleration zone and changeover zone.

Acceleration zone is the region of the track that allows the athlete to take the next leg to start increasing speed before collecting the baton.

Changeover zone is the section where baton exchange between athletes takes place. The baton should only be exchanged within the changeover zone.

8 0
3 years ago
What is the difference between a single-model production line and a mixed-model production line?
Nat2105 [25]

The unique model production line is responsible for producing identical pieces. For this purpose the balancing of the assembly line is only responsible for assembling a model throughout the line.

This is a considerable difference compared to the mixed model assembly line where many models are assembled during the same production line, that is, it produces parts or products that have slight changes accommodated in them, with slight variations in their model or products of soft variety

The choice of the type of production depends on the type of company and its own demand, always prioritizing the efficiency in the operation. Generally, the mixed model tends to be chosen when demand is very large and customer demand is required to be met. In others it is considered a plant model in which half of the line is mixed and the other one is the only model in order to keep the efficiency balanced.

6 0
3 years ago
A fluid at 300 K flows through a long, thin-walled pipe of 0.2-m diameter. The pipe is enclosed in a concrete casing that is of
andrew-mc [135]

Answer:

The correct answer is "1341.288 W/m".

Explanation:

Given that:

T₁ = 300 K

T₂ = 500 K

Diameter,

d = 0.2 m

Length,

l = 1 m

As we know,

The shape factor will be:

⇒ SF=\frac{2 \pi l}{ln[\frac{1.08 b }{d} ]}

By putting the value, we get

⇒       =\frac{2 \pi l}{ln[\frac{1.08\times 1}{0.2} ]}

⇒       =3.7258 \ l

hence,

The heat loss will be:

⇒ Q=SF\times K(T_2-T_1)

       =3.7258\times 1\times 1.8\times (500-300)

       =3.7258\times 1.8\times (200)

       =1341.288 \ W/m

3 0
3 years ago
If welding is being done in the vertical position, the torch should have a travel angle of?
siniylev [52]

Answer:

Between 35°– 45°

Explanation:

In the vertical position, Point the flame in the direction of travel. Keep the flame tip at the correct height above the base metal. An angle of 35°–45° should be maintained between the torch tip and the base metal. This angle may be varied up or down to heat or cool the weld pool if it is too narrow or too wide

4 0
2 years ago
Other questions:
  • What's mutual inductance​
    8·1 answer
  • Suppose you were a heating engineer and you wished to consider a house as a dynamic system. Without a heater, the average temper
    6·1 answer
  • I'm really bad at measurements so I don't understand this.
    12·1 answer
  • What is the function of engineering
    6·1 answer
  • Test if a number grade is an A (greater than or equal to 90). If so, print "Great!". Hint: Grades may be decimals. Sample Run En
    15·1 answer
  • 10 properties of metals?<br> ​
    10·2 answers
  • A 75-hp motor that has an efficiency of 91.0% is worn-out and is replaced by a motor that has a high efficiency 75-hp motor that
    6·1 answer
  • QUICK ASAP!!!
    6·1 answer
  • Instructions: For each problem, identify the appropriate test statistic to be use (t test or z-test). Then compute z or t value.
    14·1 answer
  • Do better then me......................................
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!