Live data from Hacker News

Solitaire with text-based interface in C

github.com

1–10 of 11 posts

Re: Solitaire with text-based interface in C

#2
I've just finished implementing my Solitaire game with curses interface in C. Solitaire was the first computer game I have played and I never got around to implementing it.

This is a writeup of how the game was made, using the vim+gcc+gdb stack.

Although working on a completely different tech stack at work, I like C, there's something zen-like about being close to the machine and almost universally portable.

Re: Solitaire with text-based interface in C

#3
post #2

I've just finished implementing my Solitaire game with curses interface in C. Solitaire was the first computer game I have played and I never got around to implementing it. This is a writeup of how the game was made, using the vim+gcc+gdb stack. Although working on a completely different tech stack at work, I like C, there's something zen-like about being close to the machine and almost universally portable.

Good post, but why not link to the post on your github.io domain? https://jborza.github.io/games/2020/07/12/solitaire-cli.html

Re: Solitaire with text-based interface in C

#4
I probably would have opted for the array representation instead of linked lists, but that is somewhat subjective thing. I do note that each card can be represented by single byte fairly easily (2 bits for suit, 4 bits for rank, 1 bit for revealed (maybe)), which would reduce memory consumption if that is concern. Thinking more of it, I think the whole board-state could be represented with 13+52 byte array, having markers between the cards to indicate different piles. Not that I'd recommend that approach unless you are extremely memory constrained, it probably would bit annoying to handle

fyi I noticed that your mallocz seems to reimplement calloc: https://pubs.opengroup.org/onlinepubs/009695399/functions/ca...

Re: Solitaire with text-based interface in C

#5
post #4

I probably would have opted for the array representation instead of linked lists, but that is somewhat subjective thing. I do note that each card can be represented by single byte fairly easily (2 bits for suit, 4 bits for rank, 1 bit for revealed (maybe)), which would reduce memory consumption if that is concern. Thinking more of it, I think the whole board-state could be represented with 13+52 byte array, having ma…

> I think the whole board-state could be represented with 13+52 byte array, having markers between the cards to indicate different piles.

A multiple-gap buffer is more difficult to handle than a linked list, yeah.

Re: Solitaire with text-based interface in C

#8
post #7

Good game and good implementation; Mac need to use ncurses and no tinfo and not sure the implication. And do not type c8, segment fault. Thought it use linked list not array ... Very good game and play a few round

Thanks for finding the bug - I haven’t caught this one! It crashes because it wasn’t checking the column id, that’s an array of piles in game_state, the piles themselves are linked lists.

Linking without tinfo shouldn’t be a problem

Re: Solitaire with text-based interface in C

#9
post #7

Good game and good implementation; Mac need to use ncurses and no tinfo and not sure the implication. And do not type c8, segment fault. Thought it use linked list not array ... Very good game and play a few round

Other than no typing c8, finish at least two full game and it is ok. Better not to play it la. Too addictive.

Re: Solitaire with text-based interface in C

#10
post #8
post #7

Good game and good implementation; Mac need to use ncurses and no tinfo and not sure the implication. And do not type c8, segment fault. Thought it use linked list not array ... Very good game and play a few round

Thanks for finding the bug - I haven’t caught this one! It crashes because it wasn’t checking the column id, that’s an array of piles in game_state, the piles themselves are linked lists. Linking without tinfo shouldn’t be a problem

Still playing it and do a pull request even, plus a further plan to upgrade yous. But the pull request has a minor bug which I fix. Life in a day of programmer I supposed.
Post reply on HN