In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to develop and realize tic-tac-toe chess in C language". The content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "how to develop and realize tic-tac-toe chess in C language".
general idea
Tic tac toe board we can generally operate as a two-dimensional array, we need to initialize the two-dimensional array, print the board, players play chess, computer chess, judge the winning or losing code, etc.
the creation of project
We created header files for function declarations, game.c files for function implementations, and test.c files for tests.
test results
Computer wins:
Player wins:
Draw:
Implementation of each function code
We implement the code for function functionality in the game.c file
void InitBoard(char Board[ROW][COL], int row, int col){ for (int i = 0; i
< row; i++) { for (int j = 0; j < col; j++) { Board[i][j] = ' '; } }}打印棋盘void DisplayBoard(char Board[ROW][COL], int row, int col){ for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { printf(" %c ", Board[i][j]); if (j < col - 1) printf("|"); } printf("\n"); if (i < row - 1) { for (int j = 0; j < col; j++) { printf("---"); if (j < col - 1) printf("|"); } } printf("\n"); }} 这里的棋盘我们只打印了井字的形状,如果为了美观,还可以进行封边,这里就留给朋友们自行实现啦。 玩家下棋void PlayMove(char Board[ROW][COL], int row, int col){ while (1) { int x = 0, y = 0; printf("请输入坐标:\n"); scanf("%d%d", &x, &y); if (x >= 1 && x = 1 && y
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.