Gobang code

It took three days , I'm a good cook , insane debug
It's really tiring not to write code carefully

** This code uses vs2019 compile
So I used it scanf_s( I know everything )
If you use another compiler, please note that the starting point is changed to scanf
#include<stdio.h> #include<stdlib.h> #include<time.h> #define ROW 3// The number of macro definition lines is 3
ROW For line ,LIE As column ( Not listed in English ) #define LIE 3// The number of macro definition columns is 3, It can also be changed to a large chessboard , But to change the game mechanism void aBoard(char
board[ROW][LIE], int row, int lie);// Initialize pieces void printBoard(char board[ROW][LIE],
int row, int lie);// Print chessboard void Playergo(char board[ROW][LIE], int row, int lie);
// People go void Computergo(char board[ROW][LIE], int row, int lie);// Computer walk char ifWin(
char board[ROW][LIE], int row, int lie);// Judge whether to win or lose void menu(void);// menu void test(
void);// void game(void);// core int main(void) { test(); return 0; } void game(
void) { char p = 0; char board[ROW][LIE] = { 0 };// I don't know why I can't use it ‘ ’; // Initialize pieces to spaces
aBoard(board, ROW, LIE); // Print chessboard printBoard(board, ROW, LIE); while (2)// wrong 0 That's fine
{ // Players play chess Playergo(board, ROW, LIE); printBoard(board, ROW, LIE); // Judge whether the player wins p =
ifWin(board, ROW, LIE); if (p != 'C') { break; } // Computer chess Computergo(board, ROW,
LIE); printBoard(board, ROW, LIE); // Judge whether the computer wins p = ifWin(board, ROW, LIE); if (p
!= 'C') { break; } } if (p == '*') { printf("YOU WIN\n"); printf("\n"); } else
if (p == '#') { printf("COMPUTER WIN!\n"); printf("\n"); } } // Game menu void menu(
void) { printf("-----------------------------------------------\n"); printf(
"-----------------------------------------------\n"); printf("***** input 1. Start the game
input 0. Exit the game *****\n"); printf("-----------------------------------------------\n");
printf("-----------------------------------------------\n"); } // Initialize chessboard void
aBoard(char board[ROW][LIE], int row, int lie) { for (int i = 0; i < row; i++) {
for (int j = 0; j < lie; j++) { board[i][j] = ' '; } } } // Print chessboard void printBoard(
char board[ROW][LIE], int row, int lie) { for (int i = 0; i < row; i++) { for (
int j = 0; j < lie; j++) { if (j < lie - 1) { printf(" %c |", board[i][j]); }
else printf(" %c ", board[i][j]); } printf("\n"); if (i < row - 1) { for (int k
= 0; k < lie; k++) { if (k < lie - 1) { printf("---|"); } else { printf("---");
} } } printf("\n"); } } // Player input void Playergo(char board[ROW][LIE], int row, int
lie) { int x = 0; int y = 0; while (1)// ditto { printf(" System prompt : Please enter the coordinates you want "); printf(
" The coordinates are separated by spaces "); scanf_s("%d%d", &x, &y); printf("\n"); // judge xy Is it legal , One is whether it exceeds , One is whether it is occupied
if (x > 0 && x < row + 1 && y>0 && y < lie + 1) { if (board[x - 1][y - 1] == ' '
) { board[x - 1][y - 1] = '*'; break; } else { printf(" Coordinates occupied , Please re-enter \n"); printf(
"\n"); } } else { printf(" Out of coordinate range , The horizontal and vertical coordinates entered are 1 reach 3;\n\n"); } } } void Computergo(char
board[ROW][LIE], int row, int lie) { int x = 0; int y = 0; printf(" This computer goes fast \n\n"
); while (1) { x = rand() % row; y = rand() % lie; if (board[x][y] == ' ') {
board[x][y] = '#'; break; } } } // Judge the outcome char ifWin(char board[ROW][LIE], int row,
int lie) { int i = 0; // Judgment line for (i = 0; i < row; i++) { if (board[i][0] == board
[i][1] && board[i][1] == board[i][2] && board[i][1] != ' ') { return board[i][1]
; } } // Judgment column for (i = 0; i < lie; i++) { if (board[0][i] == board[1][i] && board[
1][i] == board[2][i] && board[1][i] != ' ') { return board[1][i]; } } // Judge diagonal if
(board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[1][1] != ' ')
{ return board[1][1]; } if (board[2][0] == board[1][1] && board[1][1] == board[0
][2] && board[1][1] != ' ') { return board[1][1]; } return 'C'; } void test(void
) { srand((unsigned int)time(NULL)); int input = 0; do { menu(); printf("\n");
printf(" System prompt : Please select :>>>"); scanf_s("%d", &input); printf("\n"); switch (input) {
case 1: game(); break; case 0: printf(" game over \n"); break; default: printf(
" illegal input , Please re-enter \n"); break; } } while (input); }
** The following is the process of the game
My strength is limited , The game experience may not be very good
**

Do you have any suggestions to optimize the game

Technology