-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
王益龙 #17
base: master
Are you sure you want to change the base?
王益龙 #17
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
益龙,狠啊,level1已经做完了啊
#include <time.h> | ||
#include <string.h> | ||
//constants | ||
enum{ N = 1000 , sleep_time = 50}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
习惯上,常量用全大写+下划线
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
int primes[N], cnt; | ||
int sieved[N]; | ||
|
||
void get_primes(int n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
漂亮的函数原型!
level1/p09_maze/maze.c
Outdated
srand((unsigned)time(0)); | ||
c_r = c_c = 0; | ||
if (!set) set = (int *)malloc(Height * Width * sizeof(int)); | ||
for (i = 0; i < Height * Width; ++ i) set[i] = i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要一行写多条语句,不够清晰,也不方便调试打断点
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
level1/p09_maze/maze.c
Outdated
c_r = c_c = 0; | ||
if (!set) set = (int *)malloc(Height * Width * sizeof(int)); | ||
for (i = 0; i < Height * Width; ++ i) set[i] = i; | ||
if (!map) map = (int **)malloc(Height * sizeof(int *)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
} | ||
void dig() { | ||
while (1) { | ||
int p1 = find(0), p2 = find(Height * Width - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我自己喜欢分行写
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
level1/p09_maze/maze.c
Outdated
int cnt = 0; | ||
for (i = 0; i < 4; ++ i) { | ||
int nr = r + dir[i][0], nc = c + dir[i][1]; | ||
if (nr >= 0 && nr < Height && nc >= 0 && nc < Width && !map[nr][nc]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种长表达式,我有时会提到一个中间变量中,这样可以给它一个名字来表达这个表达式的意图;根据情况,有时甚至会提成一个函数
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
level1/p09_maze/maze.c
Outdated
int i; | ||
for (i = 0; i < 4; ++ i) { | ||
int nr = r + dir[i][0], nc = c + dir[i][1]; | ||
if (nr >= 0 && nr < Height && nc >= 0 && nc < Width && !map[nr][nc]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
上面那个表达式如果提成了函数,这里就可以复用了;
当然,并不需要提前预判这种情况,而是当再次看到老朋友(上面出现过的表达式)时,再重构提取函数就好了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
level1/p10_pushBoxes/pushBoxes.c
Outdated
} | ||
//箱子前方归位点 | ||
else if (NotOut(b_n_r,b_n_c) && maps[cur_map][b_n_r][b_n_c] == Dest) { | ||
maps[cur_map][n_r][n_c] = PInDest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
轻微的重复的味道
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
多谢老师指点 |
话说有人通关了我那个推箱子吗,对了,你们还能仿照我地图的格式自己DIY一个地图玩玩 |
FInished some