#Solitaire written in C for terminal

13 messages · Page 1 of 1 (latest)

urban kestrel
#

I wrote a Solitaire game in C that I'm kinda proud of but since I'm learning on my own I don't really know all the best ways to do things and one big giveaway is that the whole game is in one file that is a little bit over 1k lines.

This was originally ment to be a simple project that I was gonna use to learn vim motions and it evolved much further then I originally thought. And when I realised it it was too late to separate the whole game in to different files. Not that it's not possible but it's just a skill issue.

Here's the game repo I just created: https://github.com/d0mb1/solitaire-c

There are two screenshots of what the game looks like, one of the nerd fonts that the game relies on, binaries and the source code itself.

GitHub

solitaire written in C. Contribute to d0mb1/solitaire-c development by creating an account on GitHub.

steady bobcat
#

Looks pretty good. What standard of C are you compiling with? You’re using an empty initializer which is a C23 feature or GNU extension. If you choose to use C23 then you can use constexpr instead of those preprocessor defines.
Some of these comments seem pretty redundant, like the comment “shuffling” on the call to shuffle.
No need to call srand twice, especially since time(NULL) will probably be the same both calls. If you want better randomness I wouldn’t use rand at all tbh.
You’ve got a bunch of magic numbers in the bounds of your loops, which makes it harder to grasp what your code is intending to do

#

One file is fine, especially since all the code is related. At most, you could split up the card definitions, but there’s not really any other place to split it up

urban kestrel
#

I normally use write "gcc solitaire.c -o solitaire". When I write gcc --version I get "Apple clang version 16.0.0".
The time NULL is an oversight. The shuffle function is there twice because the deck isn't shuffled perfectly for the first time and the start/end (not sure which anymore) of the deck is the same each time.

urban kestrel
steady bobcat
#

I don’t have any on hand, since I’m not by my computer, but you should be able to just search up some alternatives. It’s just a bad function to use since quality varies by system and is generally bad

urban kestrel
steady bobcat
urban kestrel
celest cedar
urban kestrel
steady bobcat
#

You can use zig if you want. It’s a frontend for clang with different defaults

#

If you don’t want to deal with any build system just a simple shell script will do tbh