当前位置:网站首页>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");
}边栏推荐
- [conference resources] the Third International Conference on Automation Science and Engineering in 2022 (jcase 2022)
- Infiltration records of CFS shooting range in the fourth phase of the western regions' Dadu Mansion
- [eight sorts ④] merge sort, sort not based on comparison (count sort, cardinal sort, bucket sort)
- [disease detection] realize lung cancer detection system based on BP neural network, including GUI interface
- Global and Chinese market of collaborative applications 2022-2028: Research Report on technology, participants, trends, market size and share
- Basic number theory -- Gauss elimination
- Single chip microcomputer -- hlk-w801 transplant NES simulator (III)
- The first "mobile cloud Cup" empty publicity meeting, looking forward to working with developers to create a new world of computing!
- Viewing and modifying volume group attributes of Aix storage management (II)
- Deb file installation
猜你喜欢

【八大排序②】选择排序(选择排序,堆排序)

The first "mobile cloud Cup" empty publicity meeting, looking forward to working with developers to create a new world of computing!

SAP ui5 beginner tutorial XXI - trial version of custom formatter of SAP ui5

How to extract login cookies when JMeter performs interface testing

测试人进阶技能:单元测试报告应用指南

Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
![[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me](/img/b8/31a498c89cf96567640677e859df4e.jpg)
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me

Exclusive delivery of secret script move disassembly (the first time)
![[dynamic planning] interval dp:p3205 Chorus](/img/25/3dc7132e1aaa5c0eca87382692fc12.jpg)
[dynamic planning] interval dp:p3205 Chorus

学习笔记24--多传感器后融合技术
随机推荐
Hcip day 14 (MPLS protocol)
Global and Chinese markets of edge AI software 2022-2028: Research Report on technology, participants, trends, market size and share
Study note 2 -- definition and value of high-precision map
No converter found for return value of type: class
Global and Chinese markets of digital crosspoint switches and mux/demux 2022-2028: Research Report on technology, participants, trends, market size and share
How does schedulerx help users solve the problem of distributed task scheduling?
Review notes of compilation principles
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
Global and Chinese markets for supply chain strategy and operation consulting 2022-2028: Research Report on technology, participants, trends, market size and share
Infiltration records of CFS shooting range in the fourth phase of the western regions' Dadu Mansion
cookie、session、tooken
Global and Chinese market of aircraft MRO software 2022-2028: Research Report on technology, participants, trends, market size and share
2022年6月国产数据库大事记
Cookie, session, tooken
The author is more willing to regard industrial Internet as a concept much richer than consumer Internet
Keepalived introduction and installation
[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface
Global and Chinese market of wireless chipsets 2022-2028: Research Report on technology, participants, trends, market size and share
只是以消费互联网的方式和方法来落地和实践产业互联网,并不能够带来长久的发展
Creation of volume group for AIX storage management (I)