
Solitaire with text-based interface in C - axarydax
https://github.com/jborza/jborza.github.io/blob/master/_posts/2020-07-12-solitaire-cli.md
======
axarydax
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.

~~~
swagonomixxx
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](https://jborza.github.io/games/2020/07/12/solitaire-cli.html)

------
zokier
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...](https://pubs.opengroup.org/onlinepubs/009695399/functions/calloc.html)

~~~
fao_
> 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.

------
holgersindbaek
Neat. I've made an implementation of Solitaire in JS (React/HTML/GSAP) -
[https://online-solitaire.com/](https://online-solitaire.com/) \- but really
interesting how it can be done in a low-level language like C.

------
ngcc_hk
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

~~~
axarydax
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

~~~
ngcc_hk
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.

~~~
ngcc_hk
Just stop to have more idea ... like multi user ... AI study etc. and touching
for awhile. A new branch is developed as a base for my future self to work
with. Need to do more serious work for my lovely fallen place. In the mean
time, I guess I understand why again those hacker in the 70s doing text game
(and also one on cathode tube) using the Internet then. It is all addictive.
Have to stop :-)

