Klondike Solitaire for curses in 5k of C language
Main page
Intel 8080 emulator
Chess programs
Contests
Store
Retrogaming
FAQ
Links
About me
Ver en español
Klondike Solitaire for curses in 5k
by Oscar Toledo G. Jun/07/2026
I had some free time, and I noticed the 29th IOCCC started. So I decided to code an entry for the contest. If you haven't heard about the International Obfuscated C Code Contest, it is a contest running since 1984 and created by Landon Curt Noll. The objective of this contest is writing an obfuscated C program under certain size limitations specified by the rules.
You can see my previous winning entries for the IOCCC in the Contests section.
This year the maximum size is 4993 bytes (a little less than 5 kilobytes), and the number of printable characters is 2503. As there are some special rules for printable characters, there is now a tool called iocccsize for checking this.
Whenever I say obfuscated C, it is the way of writing C code in a form that does the objective but it isn't clear. For example, a simple loop counting from 1 to 10 is written like this:
#include<br>int main(void) {<br>int c;
for (c = 1; c
But using a small fraction of the C syntax power, we can do it this way:
#include<br>int main(void) {int c=1;while(printf("%d\n",c),11>++c);}
This gives you a small idea of what obfuscated C is about. Deciphering the best one liner of any IOCCC year is a challenge! And a way of testing your C knowledge.
The idea
After pondering several ideas, I decided for a Klondike Solitaire game in C language as I have coded several over my career. One for my own operating system about twenty years ago (I need to write more about this), and recently Klondike for Intellivision consoles.
In case you don't know, Solitaire was a game included in Windows 3.1 along Minesweeper. Both were a complete success because the gaming scene for Windows was almost null. Bored people using Windows 3.1 started playing Minesweeper and then Solitaire, and it was addictive! I didn't know until I played myself, and I understood the rules. I also discovered that there are several solitaire games, also known as patience, and this was the Klondike variation. I leaved it for good when I discovered that not all games could be won. In fact, mathematicians estimate that only 43% of the games with a single card deal can be won, and this number drops sharply to 18% if three cards are deal. Even if you can see all the cards it isn't so easy to win.
Klondike Solitaire in Windows 3.1 (running in PCjs Machines)
Coding it!
I started coding in Feb/06/2026, it took me three days to code the main logic in C, and I decided to use the curses library to create the cards display, use color, and added also Unicode characters to show the cards symbols. The curses library allows to control the screen for creating text interfaces without worrying about the terminal type being used.
Of course, this first version of the game was too big for the contest's limits, so I started optimizing the code. Also I had to solve the problem of the user interface for selecting and dropping the cards.
The original interface of Klondike is oriented towards moving a cursor over a card, picking it, and dropping it in another place. In fact, the legend says that Windows 3.1 included this game just to teach users how to drag&drop things with the mouse.
In order to fit in the space for the contest, my user interface has to be greatly simplified using the Tab key for selecting cards, and the Space key for dropping cards.
I don't know how to use curses
Learning curses is pretty good if you are an evil wizard... Oh sorry, I mean learning the curses library :P It felt like an eternity the learning curve for using it in the game. I discovered there are several versions of it, and I know by experience that every Linux and Mac distribution includes it in some form.
The main problem of curses is that there are way too many versions! And each operating system integrates a vaguely different version of the library. The other common problem is that the suits require UTF-8, and some curses libraries don't support it (see the Remarks). You are good with curses if you are using ASCII exclusively.
At least I found character definitions for building boxes (the cards), and Unicode provided me the symbols for the cards.
I also could use colors for red cards. Many years ago it was far more common using the ANSI/VT-52 escape sequences, but this is the type of thing that curses solves through an unified interface.
My Klondike game for curses in action
Polishing
I managed to implement a 3-card deal as an option, and also a Las Vegas scoring mode. The number of arguments when running the program selects these options (see the Remarks)
The cherry in the cake was adding a scoring system exactly like in Windows, including the bonus per time.
The source code
After several revisions and days in development, here is the source code of my Klondike Solitaire game for...