Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

王益龙 #17

wants to merge 7 commits into from

Conversation

iku-iku-iku
Copy link

FInished some

@iku-iku-iku iku-iku-iku marked this pull request as ready for review March 13, 2021 09:18
Copy link
Owner

@luckymark luckymark left a 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};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

习惯上,常量用全大写+下划线

Copy link
Author

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

漂亮的函数原型!

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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要一行写多条语句,不够清晰,也不方便调试打断点

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

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 *));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Author

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我自己喜欢分行写

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

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]) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种长表达式,我有时会提到一个中间变量中,这样可以给它一个名字来表达这个表达式的意图;根据情况,有时甚至会提成一个函数

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

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]) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面那个表达式如果提成了函数,这里就可以复用了;
当然,并不需要提前预判这种情况,而是当再次看到老朋友(上面出现过的表达式)时,再重构提取函数就好了

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

}
//箱子前方归位点
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

轻微的重复的味道

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

@iku-iku-iku
Copy link
Author

多谢老师指点

@iku-iku-iku
Copy link
Author

话说有人通关了我那个推箱子吗,对了,你们还能仿照我地图的格式自己DIY一个地图玩玩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants