当前位置:网站首页>C language to realize the three chess game
C language to realize the three chess game
2022-07-27 01:26:00 【Mr y running】
( One ): Pre writing ideas
1: First, we can create 2 Source file ,1 Head file ; Pictured

among game.c It is to realize game operation ;test.c It is to realize the logical planning of the game ;game.h Is the declaration of the record header file and its functions ;
( Two ):test.c The realization of game logic

The code for initializing the chessboard and printing the chessboard is as follows :


At that time, I was realizing vertical and --- When printing , stay printf The corresponding coordinates are added to the statement , This will cause the compiler to fail to compile ;
And in use printf Be sure to add \n, I didn't add it at that time, but I misplaced the elements of the chessboard ;

Note that variables cannot be put into while,do while And other compound statements ; Every time a player plays chess , After playing chess, the computer should use judgment sentences to judge , At this point, we can use the return value of the function to judge


Then we can construct a function to judge the success or failure of computers and players ;
Yes 4 In this case ;
1: Game player wins
2: Computers win ;
3: It ends in a draw ;
4: It's not over yet , Keep playing chess ;
Let's take a look at the relevant code :



I wrote is_win Function used x,y I mistakenly think that this variable is related to other functions in this function, which leads to an error ; Print the chessboard in front , And its players only save the chess playing information ;
When judging the draw, we first traverse the chessboard :

Then use the return value of the function to judge whether it is a draw ;

Next, most of the code is completed ; Just print the menu ;

game.h Game related statements
Finally , The game of three piece chess is finished !
边栏推荐
- MQTT----下(注意事项)
- Next generation Internet: Video Networking
- #问题反馈 手机 app 同步失败:数据仓库外部变更损坏 ipad app 也是一打开就下载仓库,然后闪退
- Unity Twitter登录接入
- Li Kou brushes 300 record posts
- ESP8266-----SNTP获取网络时间
- Surrounded area
- 集中式版本控制工具代码合并问题
- ESP8266 AP_UDP_Client
- Compile Darknet under vscode2015 to generate darknet Ext error msb3721: XXX has exited with a return code of 1.
猜你喜欢

Unity 使用NavMesh实现简易的摇杆功能

Unity twitter login access

SQL learning (3) -- complex query and function operation of tables

Longest common substring

Jenkins -- Basic -- 5.2 -- system configuration -- system configuration

5.xshell连接服务器拒绝访问,密码错误

Six ways for the Internet of things to improve our lives
![数学建模简介-从现实对象到数学建模[2]](/img/b5/595a4e9a9a59ab57f541d3e21fba49.jpg)
数学建模简介-从现实对象到数学建模[2]

ESP8266 STA_Mode

Jenkins -- Basic -- 5.3 -- system configuration -- global security configuration
随机推荐
力扣刷题量300记录帖
How does KS catch salt value? api,did?
Shortcut key introduction
ks 怎么抓salt值?api,did?
SQL learning (2) -- basic query and sorting of tables
ESP8266 AP_UDP_Server
Six ways for the Internet of things to improve our lives
MQTT协议------上
创建MDK工程
ESP8266 STA_Server
最大公约数的求法
ESP8266---JSON数据交换格式
Jenkins -- Basic -- 5.2 -- system configuration -- system configuration
Next generation Internet: Video Networking
The setup of KEIL development environment is delivered to the installation package
Unity CharacterController
Cannot find a valid baseurl for repo: HDP-3.1-repo-1
Jenkins--基础--03--安装后设置向导
1. 众数
Li Hongyi machine learning (2017 Edition)_ P6-8: gradient descent