当前位置:网站首页>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");
}边栏推荐
- [IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
- Leetcode 45 Jumping game II (2022.02.14)
- How to reflect and solve the problem of bird flight? Why are planes afraid of birds?
- Circular statements in shell programming
- Basis of deep learning neural network
- Review notes of compilation principles
- About asp Net core uses a small detail of datetime date type parameter
- [IVX junior engineer training course 10 papers to get certificates] 03 events and guessing numbers games
- XMind思维导图
- Evolution of Himalayan self-developed gateway architecture
猜你喜欢
![[IVX junior engineer training course 10 papers to get certificates] 0708 news page production](/img/ad/a1cb672d2913b6befd6d8779c993ec.jpg)
[IVX junior engineer training course 10 papers to get certificates] 0708 news page production

We should make clear the branch prediction

I'll teach you to visit Amazon RDS for a year and build a MySQL cloud database (only 10 minutes, really fragrant)
![[eight sorts ④] merge sort, sort not based on comparison (count sort, cardinal sort, bucket sort)](/img/0d/22f3f65ab9422383df9a55d0724d59.jpg)
[eight sorts ④] merge sort, sort not based on comparison (count sort, cardinal sort, bucket sort)

Day 13 of hcip (relevant contents of BGP agreement)

Creation of volume group for AIX storage management (I)

Collection: comprehensive summary of storage knowledge

How does schedulerx help users solve the problem of distributed task scheduling?

How to compress video size while adding watermark with one click?

With the acquisition of Xilinx, AMD is more than "walking on two legs" | Jiazi found
随机推荐
Cat Party (Easy Edition)
6-2漏洞利用-ftp不可避免的问题
[IVX junior engineer training course 10 papers to get certificates] 01 learn about IVX and complete the New Year greeting card
Review notes of compilation principles
Develop a simple login logic based on SSM
Global and Chinese market of safety detection systems 2022-2028: Research Report on technology, participants, trends, market size and share
[IVX junior engineer training course 10 papers] 06 database and services
AIX存储管理之逻辑卷的创建及属性的查看和修改
Han Zhichao: real time risk control practice of eBay based on graph neural network
【八大排序②】选择排序(选择排序,堆排序)
Docker安装Oracle_11g
With the acquisition of Xilinx, AMD is more than "walking on two legs" | Jiazi found
Recommend an online interface mock tool usemock
Global and Chinese markets for freight and logistics 2022-2028: Research Report on technology, participants, trends, market size and share
Upgraded wechat tool applet source code for mobile phone detection - supports a variety of main traffic modes
Global and Chinese markets of edge AI software 2022-2028: Research Report on technology, participants, trends, market size and share
Tencent cloud techo youth dream campus trip into Wuhan University
Load and domcontentloaded in JS
The 8-year salary change of testers makes netizens envy it: you pay me one year's salary per month
CTF daily question day45 sensor