当前位置:网站首页>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");
}
边栏推荐
- [dynamic planning] interval dp:p3205 Chorus
- Entrepreneurship is a little risky. Read the data and do a business analysis
- cookie、session、tooken
- Recommend an online interface mock tool usemock
- Datawhale community blackboard newspaper (issue 1)
- S32Kxxx bootloader之UDS bootloader
- Otaku wallpaper Daquan wechat applet source code - with dynamic wallpaper to support a variety of traffic owners
- Global and Chinese market of avionics systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets of beverage seasoning systems 2022-2028: Research Report on technology, participants, trends, market size and share
- 【八大排序①】插入排序(直接插入排序、希尔排序)
猜你喜欢
JMeter做接口测试,如何提取登录Cookie
XMind思维导图
Minimize the error
【图像增强】基于Frangi滤波器实现血管图像增强附matlab代码
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
ACM教程 - 快速排序(常规 + 尾递归 + 随机基准数)
[image enhancement] vascular image enhancement based on frangi filter with matlab code
Datawhale community blackboard newspaper (issue 1)
[conference resources] the Third International Conference on Automation Science and Engineering in 2022 (jcase 2022)
The first "mobile cloud Cup" empty publicity meeting, looking forward to working with developers to create a new world of computing!
随机推荐
How can programmers better plan their career development?
[IVX junior engineer training course 10 papers to get certificates] 09 chat room production
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
【图像增强】基于Frangi滤波器实现血管图像增强附matlab代码
ACM tutorial - quick sort (regular + tail recursion + random benchmark)
Liteos learning - first knowledge of development environment
Global and Chinese markets for the application of artificial intelligence in security, public security and national security 2022-2028: Research Report on technology, participants, trends, market size
SSO single sign on implementation.
Global and Chinese market of wireless chipsets 2022-2028: Research Report on technology, participants, trends, market size and share
XMIND mind map
【八大排序③】快速排序(动图演绎Hoare法、挖坑法、前后指针法)
AIX存储管理之卷组属性的查看和修改(二)
Global and Chinese market of wireless charging magnetic discs 2022-2028: Research Report on technology, participants, trends, market size and share
关于ASP.NET CORE使用DateTime日期类型参数的一个小细节
Docker installing Oracle_ 11g
Variables and constants of go language foundation
The 8-year salary change of testers makes netizens envy it: you pay me one year's salary per month
What is commercial endowment insurance? Is commercial endowment insurance safe?
Review notes of compilation principles
Recommend an online interface mock tool usemock