当前位置:网站首页>Learn C language from scratch day 025 (maze)
Learn C language from scratch day 025 (maze)
2022-07-02 01:18:00 【Hilarious Bojack】
Bachelor degree, Department of Applied Chemistry, Zhengzhou University , Graduate student, physical chemistry, Fuzhou University , After two years of camp Education , Now, I take the postgraduate entrance examination to computer .
The original intention of writing this article is to supervise yourself to learn a certain amount of programming practice every day in this way , Although the results of the preliminary examination have not yet come out . But as long as there is a glimmer of hope, it should be a hundred times as hard to prepare for the retest , I hope I won't regret any result , And only by working hard will we not regret .
Today's learning summary : Today's efficiency is higher , Code code time is also longer . Completed the two-dimensional array int and char Type learning . And I wrote the push box one day in advance , Very happy . I even felt a little bored tonight , Because I have been writing some functions in the textbook .
It's kind of boring , Is it true that programmers are all like this to have sex there . however , Have a rest , Listen to the music for a while , And decided to write something interesting , Write a maze , Then came the interest , Write as soon as you write 4 Hours .
With the deepening of learning , It is more and more difficult for the code I write to find errors based on the logic in my mind , I feel it especially today VS Of debug A powerful , Almost all the problems solved by the algorithm you think of have some errors that you can't find logical errors in your mind . All depend on VS Of debug The problem was found by monitoring variables step by step .

I found one when I was writing the tweet today bug, I try to count every move , But each count is calculated twice , Instead of imagining it step by step , Pass me debug The discovery could be getchar The problem of .
For example 36 OK, I input "d" Then press " enter ", In fact, the input is “d\0”, Two characters . Why? Maybe it's because if you use the following formula :“for(int i=0;i<10;i++)a[i]=getchar();” There is no reading \0 The problem of . however debug The second cycle will directly skip the second 36 Yes getchar The process of , I can't think of the answer , Except for \0 I can't think of any other possibilities , Tried in the 34 In line for Add a "ch!=\0" Judgment statement of , I think it's ok if ch Indeed equal to \0 You can skip , But it still doesn't work , Let me more confused .
But after thinking about it, I changed my mind , That is, the second cycle did not wasd Such characters , Then I will compare the counter with the variable j Separate , Why do I have to use j Well ? Just put it in wasd In the internal circulation of , So there is the first 42 That's ok , Sure enough, the problem was solved , Ha ha ha ha , Species debug The feeling of successfully bypassing the problem , Happy . The moment when the count is successfully displayed , I feel very satisfied . I feel like a loser .

Although it is also for this reason debug In the early morning , But instead, I have a feeling like a programmer —— All night debug. Maybe I have more experience .
I feel free to find some practical small programs , As a stage goal, writing is very interesting and fun . It can improve the sense of achievement , It can also be used as practicing skills , You can also learn some knowledge not mentioned in textbooks every time . The main purpose of my computer study is to write games , This also exactly meets my goal .
Considering that gobang is only an advanced version of the maze , So in three days , Write a Gobang to see , Take a UI Gobang interface , You can spend more time to make it look better . So time is :2.15-17 To complete the task .
Today's code surprise :
① This code for inputting the largest string made me understand return 0 The meaning of , I didn't understand why the main function should have return. Now it seems that it can be used to test whether it can be successfully implemented to the last step .

② One of the Valentine's Day gifts for Zhang , Ha ha ha , My painted heart may need anti aliasing .

③ I feel it again VS Of debug A powerful , I must blow another wave .

Today's code size :

Today's doubt record :
no
Tomorrow's learning outlook :
①2.15-2.17 Write Gobang on the day , It is required to improve the perfection of this code as much as possible .
The maze code is here , I need to take it myself .
#include <stdio.h>
#include <windows.h>
main()
{
int i=0,j=0;
int x=1,y=1,t=10000;
char ch;
char maze[50][100]={
"***************************************************************",
"*0 ********** *",
"* ****** ******** *************** ************************ *",
"* ******* ******* ** *** *",
"* ************ ************* ******* *** **************** *** *",
"* **** ******* *** **************** *** *",
"* ************************** ******* *** **************** *** *",
"* **** ******* *** **************** *** *",
"* * ***************************** *** ************ *** *",
"* **** ***************************** *** ************ ******* *",
"* **** ***************************** *** ************ ******* *",
"* * *** ************ ******* *",
"* ************************* ************ ******* *",
"****** * ** *",
"* ************************************** ** ******************",
"* ** ** *******************",
"* *********************************** ** ** *",
"* *********************************** * **********************",
"* ************************************** ",
"***************************************************************"};
for(i=0;i<50;i++)
{
if(maze[i][0]!='\0')
puts(maze[i]);
}
printf(" The remaining steps are =10000\n");
for(j=0;j<10000;j++)
{
ch=getchar(); // Be careful here that each time you enter a direction, there is also a \0 The rest of , So I cycled twice
if(ch=='w'&&maze[x-1][y]==' ')
{
maze[x][y]=' ';
maze[x-1][y]='0';
x=x-1;
t=t-1;
}
else if(ch=='a'&&maze[x][y-1]==' ')
{
maze[x][y]=' ';
maze[x][y-1]='0';
y=y-1;
t=t-1;
}
else if(ch=='d'&&maze[x][y+1]==' ')
{
maze[x][y]=' ';
maze[x][y+1]='0';
y=y+1;
t=t-1;
}
else if(ch=='s'&&maze[x+1][y]==' ')
{
maze[x][y]=' ';
maze[x+1][y]='0';
x=x+1;
t=t-1;
}
system("cls");
for(i=0;i<50;i++)
{
if(maze[i][0]!='\0')
puts(maze[i]);
}
printf(" The remaining steps are =%d\n",t);
if(y==62&&x==18)
{
break;
}
}
printf("\n\n\n\n*****************************\n");
printf("\n\n\n\nYou are the winner!\n\n\n\n");
printf("*****************************\n");
}边栏推荐
- ACM教程 - 快速排序(常规 + 尾递归 + 随机基准数)
- Excel search and reference function
- ECS project deployment
- [IVX junior engineer training course 10 papers] 06 database and services
- Bilstm CRF code implementation
- 关于ASP.NET CORE使用DateTime日期类型参数的一个小细节
- Xinniuniu blind box wechat applet source code_ Support flow realization, with complete material pictures
- Random avatar encyclopedia, multi category wechat applet source code with history_ Support traffic master
- cookie、session、tooken
- [eight sorting ③] quick sorting (dynamic graph deduction Hoare method, digging method, front and back pointer method)
猜你喜欢

Study note 2 -- definition and value of high-precision map

【疾病检测】基于BP神经网络实现肺癌检测系统含GUI界面

ACM教程 - 快速排序(常规 + 尾递归 + 随机基准数)

2022年6月国产数据库大事记

How to reflect and solve the problem of bird flight? Why are planes afraid of birds?

Viewing and modifying volume group attributes of Aix storage management (II)

GL Studio 5 安装与体验
![[IVX junior engineer training course 10 papers to get certificates] 09 chat room production](/img/a8/25215e74162b7ab3f29df65681932b.jpg)
[IVX junior engineer training course 10 papers to get certificates] 09 chat room production

How to extract login cookies when JMeter performs interface testing

Datawhale community blackboard newspaper (issue 1)
随机推荐
Creation of volume group for AIX storage management (I)
Circular statements in shell programming
Global and Chinese markets for supply chain strategy and operation consulting 2022-2028: Research Report on technology, participants, trends, market size and share
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
How does schedulerx help users solve the problem of distributed task scheduling?
技术大佬准备就绪,话题C位由你决定
Recommend an online interface mock tool usemock
只是以消费互联网的方式和方法来落地和实践产业互联网,并不能够带来长久的发展
Evolution of Himalayan self-developed gateway architecture
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
首场“移动云杯”空宣会,期待与开发者一起共创算网新世界!
Otaku wallpaper Daquan wechat applet source code - with dynamic wallpaper to support a variety of traffic owners
Two TVs
6-2漏洞利用-ftp不可避免的问题
【八大排序②】选择排序(选择排序,堆排序)
What is commercial endowment insurance? Is commercial endowment insurance safe?
Recently, three articles in the nature sub Journal of protein and its omics knowledge map have solved the core problems of biology
SQL injection for Web Security (2)
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
Load and domcontentloaded in JS