NSTRUCTIONS Write an implementation for the function VictoryCheck() in for your
ID: 3658413 • Letter: N
Question
NSTRUCTIONS Write an implementation for the function VictoryCheck() in for your Tic-Tac-Toe program.The function should take two arguments.The first argument is a single integer argument that contains the number of adjacent symbols a player must produce to win the game.The second argument should be a two-dimensional array representing the board.The number of adjacent symbols a player needs to produce the win the game is defined in the constant CONSECUTIVE_MARKS_REQUIRED.VictoryCheck() should scan through the board and determine if a player has produced the appropriate number of adjacent symbols required to win the game.The adjacent symbols can be oriented in a horizontal, vertical or diagonal fashion.VictoryCheck() should return one of the provided victory codes to the driver.Please use the provided driver code to test your function for correctness.Take note that a scenario where the two players reach a draw in the game is not provided.You SHOULD NOT modify the provided driver code.However, the drive can be modified if you wish to code a board population scenario to produced a TIE condition.Please read the provided driver code carefully before beginning to attack this problem to understand the organizational structure and identifier names you must use in your program.In particular, pay close attention to the function DisplayVictoryMessage(), which has been written for you. // INCLUDES #include // DEFINES #ifndef __TRUE_FALSE__ #define __TRUE_FALSE__ #define TRUE 1 #define FALSE 0 #endif // ROWS and COLS must be between 1 and 9 #define ROWS 7 #define COLS 7 // MARKER CODES #define MARKONE 'X' #define MARKTWO 'O' #define BLANK ' ' // VICTORY CODES #define NOWIN 0 // MARKONE and MARKTWO have not produced CONSECUTIVE_MARKS_REQUIRED // adjacent symbols and there are moves available on the board #define MARKONEVICTORY 1 // MARKONE has produced CONSECUTIVE_MARKS_REQUIRED adjacent symbols #define MARKTWOVICTORY 2 // MARKTWO has produced CONSECUTIVE_MARKS_REQUIRED adjacent symbols #define TIE 3 // MARKONE and MARKTWO have not produced CONSECUTIVE_MARKS_REQUIRED // adjacent symbols and there are no moves available on the board #define ERROR 4 // MARKONE and MARKTWO have produced CONSECUTIVE_MARKS_REQUIRED adjacent symbols #define EPIC_FAIL 5 // the logic in VictoryCheck() has produced an impossible combination of // return code indicators // GAME PARAMETER CODES #define CONSECUTIVE_MARKS_REQUIRED 3 // PROTOTYPES void InitializeBoard(char[ROWS][COLS]); void DisplayBoard(char[ROWS][COLS]); int PlayerMove(int, int, char[ROWS][COLS], char); int VictoryCheck(int, char[ROWS][COLS]); void DisplayVictoryMessage(int); // MAIN int main() { // declare variables char board[ROWS][COLS]; // PRODUCE A NOWIN CONDITION // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKONE); PlayerMove(1, 2, board, MARKONE); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // PRODUCE A HORIZONTAL VICTORY // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKONE); PlayerMove(1, 2, board, MARKONE); PlayerMove(1, 3, board, MARKONE); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // PRODUCE A VERTICAL VICTORY // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKTWO); PlayerMove(2, 1, board, MARKTWO); PlayerMove(3, 1, board, MARKTWO); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // PRODUCE A DIAGONALDOWN VICTORY // initialize board InitializeBoard(board); // populate board PlayerMove(1, 1, board, MARKONE); PlayerMove(2, 2, board, MARKONE); PlayerMove(3, 3, board, MARKONE); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // PRODUCE A DIAGONALUP VICTORY // initialize board InitializeBoard(board); // populate board PlayerMove(3, 1, board, MARKTWO); PlayerMove(2, 2, board, MARKTWO); PlayerMove(1, 3, board, MARKTWO); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // PRODUCE A MULTIPLE PLAYER VICTORY // initialize board InitializeBoard(board); // populate board PlayerMove(4, 1, board, MARKONE); PlayerMove(4, 2, board, MARKONE); PlayerMove(4, 3, board, MARKONE); PlayerMove(3, 1, board, MARKTWO); PlayerMove(2, 2, board, MARKTWO); PlayerMove(1, 3, board, MARKTWO); // display the board DisplayBoard(board); // display victory message DisplayVictoryMessage( VictoryCheck(CONSECUTIVE_MARKS_REQUIRED, board) ); // exit program return 0; } // FUNCTION IMPLEMENTATIONS void InitializeBoard(char board[ROWS][COLS]) { for(int i=0; i" ); for(int j=0; j<= 0 || col <= 0 || row >= ROWS || col >= COLS ) { printf( "THE MOVE IS NOT ON THE BOARD " ); return FALSE; } else if (board[row-1][col-1] == MARKONE || board[row-1][col-1] == MARKTWO) { printf( "THAT SPACE IS ALREADY OCCUPIED " ); return FALSE; } else { board[row-1][col-1]=symbol; return TRUE; } return FALSE; } int VictoryCheck(int winRequirement, char board[ROWS][COLS]) { // YOUR IMPLEMENTATION GOES HERE } void DisplayVictoryMessage(int victoryCode) { // display the victory condition results switch(victoryCode) { case NOWIN: printf("There is still no winner. "); break; case MARKONEVICTORY: printf("MARKONE has won the game. "); break; case MARKTWOVICTORY: printf("MARKTWO has won the game. "); break; case TIE: printf("The game is a draw. "); break; case ERROR: printf("Something bad happened... MARKONE and MARKTWO have both won. "); break; case EPIC_FAIL: printf("Something bad happened... VictoryCheck() has produced an impossible combination of return code indicators. "); break; default: printf("DisplayVictoryMessage() was passed an invalid victoryCode. "); } }Explanation / Answer
Sorry but I an unable to figure out the question here!! :(
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.