Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need this in C++. The mission of this assignment is to realize a traditional C

ID: 3691960 • Letter: I

Question

I need this in C++. The mission of this assignment is to realize a traditional Connect Four game. Your first task is to add the logic to check the status of the game, i.e., which player is winning. Note that unlike the tic-tac-toe game demonstrated in class, finding out the presence of "connect four" on all board positions is extremely inefficient. Instead, the check mechanism must start at the point in which the mark is placed. For instance, to check the horizontal direction, the logic needs to inspect the right (eastbound) direction and the left (westbound) direction to count the "consecutive" marks to be found along the way walking through the board location. The posted template has already implemented a board structure with a traditional size (6 x 7) 2-dimensional cells. Study the already implemented horizontal direction check and extend it to realize for other directions. This is not difficult but take extra care to manipulate "row" and "column" indexes. They are very fragile and causing strange errors. You can also find a logic to "count" a "value" of the position you visited, which will be utilized for the development of the intelligence in your logic. The heuristics approach applied here (Akira's version) is the next computation: The place to be marked will have a unit score (1 point) for every empty position reachable from that position; up to 4 positions apart from that position are considered if no opponent is blocking the direction. The same mark will have a double score (2 points); having three same marks and one empty space is considered to be a winning position and 50 points are added; having four consecutive same marks is "connect four" and 100 points are added, The total score for all the four (horizontal, vertical, and two diagonal) directions originated at a chosen position is considered as a "score" of the turn. The computation occurs for the machine's turn of 'x' after human placed 'o' to the column (f). If the machine chooses the column (a), there is no other mark of 'x' found in any direction and so the left of the pair of H(orizontal), V(ertical), L(eftup), and R(ightup) directions have the value 0. There are 3 positions empty above the mark of 'x' at the bottom row. Therefore, the score is (number of 'x' marks) 1 x 2 + (number of reachable empty positions) 3 = 5. If the machine chooses the column (b), the computation is 4 x 2 + 11 + 50 = 69. Notice that the extra 50 points are added because 3 'x' marks are found in Leftup-diagonal in columns (b), (d), (e). The report above shows the number of the same mark one less than the actual count observed. You need to compute each possible turn among the choices (a) through (g) based on this defined rule. Place the turn to the board, compute scores, and then erase the placed turn using an "erase" method already implemented. The intention is to select the turn with the highest score computed. However, choosing the identified turn may be too hasty because that choice for you (or machine) may not be damaging the opponent but rather contributing to the winning position of the opponent. The right way is to apply the "simulated" motion of each turn the machine can make, followed by the same simulated motion at the human-side to evaluate how the human-side would be losing based on the same computation. The iterative round of this simulated implementation is the so-called "Minimax with alpha-beta pruning method" in the Artificial Intelligence Course and this is beyond this course's material.

Explanation / Answer

Answer:

#include <iostream.h>
#include <stdlib.h>
#include <windows.h>

#define DISPLAYED_HEIGHT 6
#define DISPLAYED_WIDTH 7

void design_board();
void move_player(int player);
bool find_for_sucess_winner(int x, int y, int player);
bool find_for_combination_Southwest_Northeast(int x, int y, int player);
bool find_for_combination_Northwest_Southeast(int x, int y, int player);
bool search_combination_as_vertical(int x, int y, int player);
bool search_combination_as_horizontal(int x, int y, int player);

int information_board[DISPLAYED_HEIGHT][DISPLAYED_WIDTH] = {{0,0,0,0,0,0,0},
                                 {0,0,0,0,0,0,0},
                                 {0,0,0,0,0,0,0},
                                 {0,0,0,0,0,0,0},
                                 {0,0,0,0,0,0,0},
                                 {0,0,0,0,0,0,0}};

int CompletedMoveofX, CompletedMoveofY;

int main()
{
   int counter = 0;
   bool winner = false;

   srand(ReadCountofMarked());
   cout << "Please choose a number from 1-7" << endl;
   cout << "| 1| 2| 3| 4| 5| 6| 7" << endl;

   design_board();

   for (int i = 0; i < 21; i++)
   {
      move_player(1);
      design_board();
      winner = find_for_sucess_winner(CompletedMoveofX, CompletedMoveofY, 1);
      if (winner)
      {
         cout << " You Won!!!!!!!!!!!!!" << endl;
         break;
      }

      move_player(2);
      design_board();
      winner = find_for_sucess_winner(CompletedMoveofX, CompletedMoveofY, 2);
      if (winner)
      {
         cout << " You Won!!!!!!!!!!" << endl;
         break;
      }
   }

   system("PAUSE");
   return 0;
}

void design_board()
{
   cout << endl;

   for (int y = 0; y < DISPLAYED_HEIGHT; y++)
   {
      for (int x = 0; x < DISPLAYED_WIDTH; x++)
      {
         cout << "| ";
         if (information_board[y][x] == 0) cout << " ";
         else if (information_board[y][x] == 1) cout << "X";
         else if (information_board[y][x] == 2) cout << "O";
      }
      cout << " ---------------------" << endl;
   }
}

void move_player(int player)
{

   int option;
   cout << " Player" << player << ", choose a number from 1 - 7: ";
   cin >> option;



   if (cin.fail())
   {
      cout << "Error occurred.!";
      exit(1);
   }

   while (option > DISPLAYED_WIDTH || option <=0)
   {
      cout << " Please choose again: ";
      cin >> option;
   }

   int number = 0;
   while (information_board[(DISPLAYED_HEIGHT-1)-number][(option-1)] != 0)
   {
      number++;
      if (number > (DISPLAYED_HEIGHT-1))
      {
         cout << " Please choose again: ";
         cin >> option;
         number = 0;
      }
   };

   information_board[(DISPLAYED_HEIGHT-1)-number][option-1] = player;
   CompletedMoveofY = (DISPLAYED_HEIGHT-1)-number;
   CompletedMoveofX = option-1;
}

bool find_for_sucess_winner(int x, int y, int player)
{
   bool winner;

   if (find_for_combination_Southwest_Northeast(x,y,player)) return true;
   else if (find_for_combination_Northwest_Southeast(x,y,player)) return true;
   else if (search_combination_as_vertical(x,y,player)) return true;
   else if (search_combination_as_horizontal(x,y,player)) return true;
   else return false;
}

bool find_for_combination_Southwest_Northeast(int x, int y, int player)
{
   int marks = 1;
   int count = 1;

   while((y-count >= 0) && (x+count < DISPLAYED_WIDTH))
   {
      if (information_board[y-count][x+count] == player)
      {
         marks++;
         count++;
      }
      else break;
   }

   count = 1;
   while((y+count < DISPLAYED_HEIGHT) && (x-count >=0))
   {
      if (information_board[y+count][x-count] == player)
      {
         marks++;
         count++;
      }
      else break;
   }

   if (marks == 4) return true;
   else return false;
}

bool find_for_combination_Northwest_Southeast(int x, int y, int player)
{
   int marks = 1;
   int count = 1;

   while((y+count >= 0) && (x+count < DISPLAYED_WIDTH))
   {
      if (information_board[y+count][x+count] == player)
      {
         marks++;
         count++;
      }
      else break;
   }

   count = 1;
   while((y-count < DISPLAYED_HEIGHT) && (x-count >=0))
   {
      if (information_board[y-count][x-count] == player)
      {
         marks++;
         count++;
      }
      else break;
   }

   if (marks == 4) return true;
   else return false;
}

bool search_combination_as_vertical(int x, int y, int player)
{
   int marks = 1;
   int count = 1;

   while(y+count >= 0 && y+count < DISPLAYED_HEIGHT)
   {
      if (information_board[y+count][x] == player)
      {
         marks++;
         count++;
      }
      else break;
   }

   if (marks == 4) return true;
   else return false;
}

bool search_combination_as_horizontal(int x, int y, int player)
{
   int marks = 1;
   int count = 1;

   while((x+count >= 0) && (x+count < DISPLAYED_WIDTH))
   {
      if (information_board[y][x+count] == player)
      {
         marks++;
         count++;
      }
      else break;
   }

   count = 1;
   while((x-count < DISPLAYED_WIDTH) && (x-count >=0))
   {
      if (information_board[y][x-count] == player)
      {
         marks++;
         count++;
      }
      else break;
   }

   if (marks == 4) return true;
   else return false;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote