Question

In: Computer Science

For a game that takes user input of certain letters, Upper: O,C,I,Z; Lower: o,c,i,z. The board...

For a game that takes user input of certain letters, Upper: O,C,I,Z; Lower: o,c,i,z. The board is a 4 by 4 matrix and the numbers on the right are the positon that correspond with the dots. So if player 2 statisfies the requirement for the winning condition. Winning conditions being 4 letters in a row of (all upper case-- Z I C O ), (all straight-line-- Z I i I), (all consonants - Z z C c), (all curved-- C o O c), (all vowels-- I i O o). Using C++, how does one create a function that returns if there winning condition in the board.
      ---------    Square #  
     | . . . . |  1  2  3  4 
     | o I i O |  5  6  7  8 
     | . . . . |  9 10 11 12 
     | . . . . | 13 14 15 16 
      --------- 

^^ this shows a possible winning move. You can win with a row or a column or diagonal or corners if it matches winning conditions. So you can also win if those letters were vertically or diagonally or even in four corners.

Solutions

Expert Solution

Screenshot

Program

#include <iostream>
#include<string>
using namespace std;

//Function prototype
bool checkWinner(char board[4][4]);
int main()
{
   //Test board
   char board[4][4] = { {'.','.','.','.'},{'o','I','i','O'},{'.','.','.','.'},{'.','.','.','.'} };
   //Check winner
   if (checkWinner(board)) {
       cout << "Game completed!!!\n";
   }
   else {
       cout << "Game not completed!!!\n";
   }
}
//Function check winning condition
bool checkWinner(char board[4][4]) {
   string str = "";
   string winningStr1 = "ZICO", winningStr2 = "ZIiI", winningStr3 = "ZzCc", winningStr4 = "CoOC", winningStr5 = "IiOo";
   //Horizontal check
   for (int i = 0; i < 4; i++) {
       str = "";
       for (int j = 0; j < 4; j++) {
           str += board[i][j];
       }
       if (str == winningStr1 || str == winningStr2 || str == winningStr3 || str == winningStr4 || str == winningStr5) {
           return true;
       }
   }
   //Vertical check
   for (int i = 0; i < 4; i++) {
       str = "";
       for (int j = 0; j < 4; j++) {
           str += board[j][i];
       }
       if (str == winningStr1 || str == winningStr2 || str == winningStr3 || str == winningStr4 || str == winningStr5) {
           return true;
       }
   }
   //Diagonal
   str = "";
   for (int j = 0; j < 4; j++) {
       str += board[j][j];
   }
   if (str == winningStr1 || str == winningStr2 || str == winningStr3 || str == winningStr4 || str == winningStr5) {
       return true;
   }
   //Backword
   str = "";
   for (int j = 3; j >=0; j--) {
       str += board[j][j];
   }
   if (str == winningStr1 || str == winningStr2 || str == winningStr3 || str == winningStr4 || str == winningStr5) {
       return true;
   }
   return false;
}


Related Solutions

In a c programming Write a program that converts upper case letters to lower case letters...
In a c programming Write a program that converts upper case letters to lower case letters or vice versa: Enter a sentence: What a GREAT movie is! Converted sentence: wHAT_A_great_MOVIE_IS_ Convert all non-alphabetical letters to ‘_’
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Write a program in JAVA that prompts the user for a lower bound and an upper...
Write a program in JAVA that prompts the user for a lower bound and an upper bound. Use a loop to output all of the even integers within the range inputted by the user on a single line.
OBJECTIVE C 2) // Create a small app that takes user input and performs a useful...
OBJECTIVE C 2) // Create a small app that takes user input and performs a useful calculation with that user input // - make sure that absolutely no input crashes the app. // - Use layout constraints to make sure the app looks good in portraint and landscape mode, as well as on small and large devices.
IN C++ PLEASE Requirements Write a program that takes in user input of two integer numbers...
IN C++ PLEASE Requirements Write a program that takes in user input of two integer numbers for height and width and uses a nested for loop to make a rectangle out of asterixes. The creation of the rectangle (i.e. the nested for loop) should occur in a void function that takes in 2 parameters, one for height and one for width. Make sure your couts match the sample output (copy and paste from those couts so you don't make a...
For a standard normal curve, find the z scores for the following: the lower and upper...
For a standard normal curve, find the z scores for the following: the lower and upper z-scores for the middle .7994
The goal of the game (program) is let a user input a random number in the...
The goal of the game (program) is let a user input a random number in the range of 0-10, and then give the user feedback as to whether this number is the same, bigger or smaller than the one the computer generated. Given this, the second task is to refine the program we just created so that the program compares the user's input with the secret number to If the user's input is equal to the number, print out the...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Write a Java application with a JavaFXGUI that takes a String input by the user and...
Write a Java application with a JavaFXGUI that takes a String input by the user and shows whether the string contains all 26 letters of the (English version of the Latin) alphabet. For example, "Pack my box with five dozen liquor jugs" contains all 26 letters, but "The quick frown box jumps over the hazy log" does not contain a d. It does not matter whether one or more letters appear more than once. The GUI needs, at minimum, a...
Hello, I stuck doing c++ program The program will be recieved from the user as input...
Hello, I stuck doing c++ program The program will be recieved from the user as input name of an input file and and output.file. then read in a list of name, id# and score from input file (inputFile.txt) and initilized the array of struct. find the student with the higher score and output the students info in the output file obtain the sum of all score and output the resurl in output file. prompt the user for a name to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT