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
Assuming the point estimate in Problem 6.36 is the true population parameter, what is the probability that a particular assay, w
sp2606 [1]

Complete Question

The complete question is shown on the first uploaded image

Answer:

The probability is 0.958

Explanation:

The explanation is shown on the second and third uploaded image

3 0
4 years ago
A steel bar is 150 mm square and has a hot-rolled finish. It will be used in a fully reversed bending application. Sut for the s
Xelga [282]

Answer:

See explanation

Explanation:

Given The bar is square and has a hot-rolled finish. The loading is fully reversed bending.

Tensile Strength

Sut: 600 MPa

Maximum temperature

Tmax: 500 °C

Bar side dimension

b: 150 mm

Alternating stress

σa: 100 MPa

Reliability

R: 0.999 Note 1.

Assumptions Infinite life is required and is obtainable since this ductile steel will have an endurance limit. A reliability factor of 99.9% will be used.

Solution See Excel file Ex06-01.xls.

1 Since no endurance-limit or fatigue strength information is given, we will estimate S'e based on the ultimate tensile strength using equation 6.5a.

S'e: 300 MPa = 0.5 * Sut

2 The loading is bending so the load factor from equation 6.7a is

Cload: 1

3 The part size is greater than the test specimen and the part is not round, so an equivalent diameter based on its 95% stressed area must be determined and used to find the size factor. For a rectangular section in nonrotating bending, the A95 area is defined in Figure 6-25c and the equivalent diameter is found from equation 6.7d

A95: 1125 mm2 = 0.05 * b * b Note 2.

dequiv: 121.2 mm = SQRT(A95val / 0.0766)

and the size factor is found for this equivalent diameter from equation 6.7b, to be

Csize: 0.747 = 1.189 * dequiv^-0.097

4 The surface factor is found from equation 6.7e and the data in Table 6-3 for the specified hot-rolled finish.

Table 6-3 constants

A: 57.7

b: -0.718 Note 3.

Csurf: 0.584 = Acoeff * Sut^bCoeff

5 The temperature factor is found from equation 6.7f :

Ctemp: 0.710 = 1 - 0.0058 * (Tmax - 450)

6 The reliability factor is taken from Table 6-4 for R = 0.999 and is

Creliab: 0.753

7 The corrected endurance limit Se can now be calculated from equation 6.6:

Se: 69.94 MPa = Cload * Csize * Csurf * Ctemp *

Creliab * Sprme

Let

Se: 70 MPa

8 To create the S-N diagram, we also need a value for the estimated strength Sm at 103 cycles based on equation 6.9 for bending loading.

Sm: 540 MPa = 0.9 * Sut

9 The estimated S-N diagram is shown in Figure 6-34 with the above values of Sm and Se. The expressions of the two lines are found from equations 6.10a through 6.10c assuming that Se begins at 106 cycles.

b: -0.2958 Note 4.

a: 4165.7

Plotting Sn as a function of N from equation 6.10a

N Sn (MPa)

1000 540 =aa*B73^bb

2000 440

4000 358

8000 292

16000 238

32000 194

64000 158

128000 129

256000 105

512000 85

1000000 70

FIGURE 6-34. S-N Diagram and Alternating Stress Line Showing Failure Point

10 The number of cycles of life for any alternating stress level can now be found from equation 6.10a by replacing σa for Sn.

At N = 103 cycles,

Sn3: 540 MPa = aa * 1000^bb

At N = 106 cycles,

Sn6: 70 MPa = aa * 1000000^bb

The figure above shows the intersection of the alternating stress line (σa = 100 MPa) with the failure line at N = 3.0 x 105 cycles.

8 0
3 years ago
Who's your favorite singer and WHT your favorite song​
Anna007 [38]

Answer:

and my favorite song is popular loner

Explanation:

my favorite rapper is rod wave

6 0
3 years ago
Read 2 more answers
Kinetic energy is defined as energy of an object in:
Murrr4er [49]

your answer is c. motion

5 0
3 years ago
Read 2 more answers
A car travels from A, due north to a town B 4 km away. It then travels due east until it arrives town C 5 km from B. determine t
morpeh [17]

Answer:

A to C = 6.4 km

Explanation:

A to B = 4 km

B to C = 5 km

A to C =  using pythagorean theorem

a² + b² = c²

a = A to B = 4

b = B to C = 5

c = A to C

c² = 4² + 5²

c = 6.4 km (A to C)

8 0
3 years ago
Other questions:
  • Consider a circular grill whose diameter is 0.3 m. The bottom of the grill is covered with hot coal bricks at 961 K, while the w
    10·1 answer
  • A pipe of 10 cm inner diameter is used to send crude oil over distance of 400 meters. The entire pipe was laid horizontal. The v
    5·1 answer
  • A 2.599 g sample of a new organic material is combusted in a bomb calorimeter. The temperature of the calorimeter and its conten
    13·1 answer
  • What is the difference between a job and a profession
    9·1 answer
  • Which of the following is the correct definition of mechanical energy?
    9·2 answers
  • A town is designing a rectangular, 4m deep settling tank for treating surface water intake. The tank will have a flow velocity o
    14·1 answer
  • Can a real refrigerator have higher COP than the COP of the Carnot refrigerator?
    7·2 answers
  • When could you use the engineering design process in your own life?
    9·1 answer
  • How much energy in joule is added to a 12 g of sample of aluminum (c=0.897 J/g ◦C) to raise the temperature from 20 ◦C to 45 ◦C?
    14·1 answer
  • Reverse Engineering: Structural Analysis
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!