21.4k views
1 vote
creating win cases in this tic tac toe game and how to split each win case in a function and call it properly in the main function. Currently all of my win cases are in bool detectGameOver(char board[][MAX_WIDTH], int n). Please email me if you would like the actual file.

User Fryguybob
by
8.5k points

1 Answer

4 votes

Final answer:

To split each win case in a function, define separate functions for each win condition (rows, columns, diagonals) and call them in the main function.

Step-by-step explanation:

To split each win case in a function, you can define separate functions for each win condition and call them in the main function. Here's an example:

bool checkRows(char board[][MAX_WIDTH], int n) {
// code to check win condition for rows
}

bool checkColumns(char board[][MAX_WIDTH], int n) {
// code to check win condition for columns
}

bool checkDiagonals(char board[][MAX_WIDTH], int n) {
// code to check win condition for diagonals
}

bool detectGameOver(char board[][MAX_WIDTH], int n) {
// call the separate functions to check win conditions
if (checkRows(board, n) || checkColumns(board, n) || checkDiagonals(board, n)) {
return true;
}

// rest of the code
}

This way, you have a separate function for each win condition, and you can call them in the main function to check if any win condition is satisfied. Remember to implement the code for each win condition in the respective functions.

User Dmytroy
by
8.6k points