You are not logged in.

#1 2015-05-25 16:24:06

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

Presenting c2048 by me (C code)

I've recently taken up programming again, and am in a bit of a pickle, as I don't really know anyone who are experienced enough to evaluate my code, provide tips and pointers and such, thus I hope that someone here may be able to, and of course be interested in helping.

I don't really know if such a plea is appropriate, but if nothing else, it's a fun little toy, so check it out. I may even make it an AUR thing, if I can figure out how.

Anyway, while it's only 200-300 lines of code, I thought it best not to post it here, and I finally figured out github, sort of, so here's the link: https://github.com/zacariaz/c2048


Anyway, if you got something to say, anything really, I'm very interested indeed.


Best regards.


update:
although there are still things to do, the only important stuff left is the interface, which I've tried to do my best with, but keeping it within my desired confines of 24 line by 80 characters, I find it difficult to figure out a way to make it pretty. Any ideas are welcome.

Last edited by zacariaz (2015-05-26 20:19:57)


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

#2 2015-05-25 19:53:09

smiszym
Member
Registered: 2014-04-04
Posts: 14

Re: Presenting c2048 by me (C code)

Well, the game runs well for me. As it's really simple and well-known, I'll say more about the code.

It looks quite reasonably. However, I would recommend that board be a simple array of ints instead of array of pointers to ints. You wouldn't need to malloc and free.

Functions GetScore() and GetMoves() are unneeded, as you have direct access to these variables: https://github.com/zacariaz/c2048/blob/ … .h#L10-L11.

You've got a nice habit of commenting everything. Don't repeat the code in comments, like here. But meaningful comments are precious, like here.

Good luck

Offline

#3 2015-05-25 20:41:39

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

Re: Presenting c2048 by me (C code)

smiszym wrote:

Well, the game runs well for me. As it's really simple and well-known, I'll say more about the code.

It looks quite reasonably. However, I would recommend that board be a simple array of ints instead of array of pointers to ints. You wouldn't need to malloc and free.

Functions GetScore() and GetMoves() are unneeded, as you have direct access to these variables: https://github.com/zacariaz/c2048/blob/ … .h#L10-L11.

You've got a nice habit of commenting everything. Don't repeat the code in comments, like here. But meaningful comments are precious, like here.

Good luck

As for Getscore() and GetMoves, you are of course correct. I will take care of that at some point.

As for the board, there's a very good reason why I'm doing what I'm doing, though it's easy to miss.
In simple terms, only 16 of the 64 declared pointers gets allocated memory, while the remaining are pointed such I have access to 4 rotated boards.

I have considered having a separate board also, and thus eliminate the need to allocate memory, and also the need for Initialize() and Finalize(), I only just now realize, so it goes without saying that I will also take care of that. It should be relatively easy to do.

And sadly you're quite wrong when it comes to my habits, as I usually make very little effort to comment. wink
That being said, I see what you mean, and I will try to make a bigger effort.


Thanks for the comeback.

edit:
Come to think of it, I will still need Initialize, unless someone can suggest an alternative solution for linking the 4 boards together.

edit2:
It is done.

Last edited by zacariaz (2015-05-25 21:00:25)


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

#4 2015-05-26 19:23:32

smiszym
Member
Registered: 2014-04-04
Posts: 14

Re: Presenting c2048 by me (C code)

I may have missed something when it comes to the boards (that they're linked), because I just flicked through the code, without understanding it deeply smile

Happy coding!

Offline

#5 2015-05-26 19:49:18

zacariaz
Member
From: Denmark
Registered: 2012-01-18
Posts: 539

Re: Presenting c2048 by me (C code)

smiszym wrote:

I may have missed something when it comes to the boards (that they're linked), because I just flicked through the code, without understanding it deeply smile

Happy coding!

It's easy to miss, and I'm quite sure I would have missed it my self, were the roles reverse. wink


I am a philosopher, of sorts, not a troll or an imbecile.
My apologies that this is not always obvious, despite my best efforts.

Offline

Board footer

Powered by FluxBB