5 ms·
Solitaire with text-based interface in C
- axarydax 6y agoI'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 6y agoGood 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 6y agoI 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/calloc.html https://pubs.opengroup.org/onlinepubs/009695399/functions/ca...
- fao_ 6y ago> 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 6y agoNeat. 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 6y agoGood 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 6y agoThanks 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 6y agoStill 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 6y agoJust 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 :-)
- ngcc_hk 6y agoOther than no typing c8, finish at least two full game and it is ok. Better not to play it la. Too addictive.