A Blackjack back-end inspired by GNU Chess. LibreBlackjack emulates a blackjack dealer, deals cards and understands commands such as hit or stand. The idea is that one or more players can talk to LibreBlackjack either in an interactive or automated way through the standard input, named pipes, TCP sockets or by being dynamically loaded from shared objects. These players can be actual human players playing in real-time through a front-end (a GUI application, a web-based interface, a mobile app, etc.) or robots that implement a certain betting and playing strategy playing as fast as possible to study and analyze game statistics.

I am often surprised that when people drive down two-lane roads, they will trust complete strangers in the oncoming lane not to swerve into their lane causing a head-on collision; but they will not trust mathematicians to create the correct strategy for Blackjack.

Norman Wattenberger, Modern Blackjack, 2009

Now you do not have to trust other people anymore. You just need to trust the back-end programmed in LibreBlackjack, which if of course free and open software. Once you trust the blackjack engine is fair, you can model and simulate any blackjack situation you want, playing millions of times a certain hand (say a sixteen against a ten) in different ways (say hitting or standing) to obtain you own conclusions.

The main objective is research and optimization of playing and betting strategies depending on

  • particular table rules (number of decks, hit on soft 17, double after split, etc.),
  • card counting strategies
  • risk of ruin
  • removal of cards
  • arranged shoes

These automatic players can range from simple no-bust or mimic-the-dealer hitters or standers, up to neural-networks trained players taking into account every card being dealt passing through basic strategy modified by traditional card counting mechanisms.

1 Clone

Clone the mercurial repository from Bitbucket:

hg clone ssh://

2 Bootstrap

After cloning the repository, run the script to initialize Autoconf & friends and to gather some information about versioning from Mercurial

$ ./

3 Compile

Configure and make as usual:

$ ./configure
$ make

Note that LibreBlackjack depends on two optional GNU libraries:

4 Test suite

Run as test suite to check the code work as expected.

$ make check

The subdirectory players contains some automatic players that play against LibreBlackjack. These players are coded in different languages and communicate with LibreBlackjack in a variery of ways in order to illustrate the design basis:

  • 00-always-stand, using the UNIX tool yes this player always says “stand” into the standard output (which is piped to libreblackjack’s standard input) no matter what the cards are
  • 05-no-bust is a PERL-based player does not bust (i.e. hits if the hard total is less than twelve) that receives tha cards through the standard input but draws or stands using a FIFO to talk back to the dealer
  • 08-mimic-the-dealer does tha same the dealer do (hits soft seventeens). It is implemented in AWK using two FIFOs.
  • 22-strategy-from-file reads the following text files

    • split.txt
    • soft_double.txt
    • hard_double.txt
    • soft_hit.txt
    • hard_hit.txt

and then plays accordingly. By default they contain the basic strategy, but the files can be modified at will. This a player coded in C and uses messaque queues to talk to the dealer.

5 Play!

Run LibreBlackjack with no arguments to play Blackjack interactively in ASCII mode


Type help to get it.

6 Licensing

LibreBlackjack is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

7 Further information

Home page:
Mailing list and bug reports: (you need to subscribe first at )
Follow us: Twitter YouTube LinkedIn Bitbucket

libreblackjack is copyright (C) 2016 Jeremy Theler
libreblackjack is licensed under GNU GPL version 3 or (at your option) any later version.
libreblackjack is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
See the file COPYING for copying conditions.