/NIST-Blackjack

Blackjack in Fortran by NIST--with an intentional error

Primary LanguageFortranMIT LicenseMIT

NIST Blackjack

Actions Status

For a study on cyclomatic complexity and methods to detect errors, Fortran and C code were provided by NIST. That code had syntax errors bad enough to not compile in contemporary compilers, so the syntax errors were fixed. Also, function "Mix" that shuffles the cards was not defined in the article; we provide Fisher-Yates Shuffle algorithm for this.

Build

cmake -B build

cmake --build build

Then run the respective programs by

build/f_blackjack

or

build/c_blackjack

For f_blackjack the command line flag -d enables debug mode, where you can set the value of the next card.

Implementations

As noted in the summary, we provided syntax corrections to the original code, which was not usable otherwise

C

The 1996 NIST 500-235 publication "Structured Testing: A Testing Methodology Using the Cyclomatic Complexity Metric" tries to do a line-by-line conversion from Fortran. We fixed the syntax errors in blackjack.c and use the Fortran implementations of Mix and Hit in the C program.

Fortran 90

The 1982 NIST 500-99 publication "Structured Testing: A Software Testing Methodology Using the Cyclomatic Complexity Metric" did a legacy FORTRAN implementation that was needlessly verbose and wasn't easily usable from C. We minimally updated the NIST blackjack code to Fortran 90 syntax, using Fortran 2003 bind(c) for convenience, as is generally recommended. The reusable code and main Fortran program are provided here and compatible with any Fortran compiler.