Download Latest Version GABlackjack1.1.zip (137.4 kB)
Email in envelope

Get an email when there's a new version of Genetic Algorithms Engine - Blackjack

Home
Name Modified Size InfoDownloads / Week
ReadMe.txt 2014-12-09 5.4 kB
GABlackjack1.1.zip 2014-12-09 137.4 kB
Totals: 2 Items   142.9 kB 0
========================================================================
       CONSOLE APPLICATION : GABlackjack
========================================================================

Project Description

This project is a Genetic Algorithm engine able to be reused for other projects with minimal
additional programming.  The Genetic Algorithm engine supports various mutation rates, ranked
parental selection, stochastic sampling parental selection, cyclic crossover, crossover at each
gene, cloning the best individual(s) each generation, and creating random individuals each
generation.  To use GA to search for a desired problem's solution, one needs only program a
fitness function, the project settings, and a few virtual functions.  All code was written in C++
with Visual Studio 6.0 and Visual Source Safe 6.0 for the Windows platform.
The engine currently evolves blackjack basic strategy by playing many hands of blackjack for the
fitness evaluation.  The project is at a functional stage and evolves a strategy similar to, yet
somewhat different from basic strategy.


/////////////////////////////////////////////////////////////////////////////

HOW TO USE THIS SOFTWARE

/////////////////////////////////////////////////////////////////////////////

The executable GABlackjack_Demo.exe provided is a quick demo (~5 minutes).  The output of each
generation is saved as text files in the same directory as the .exe.

The executable GABlackjack_Long.exe provided is the full fitness evaluation (~8 hours).
The output of each generation is saved as text files in the same directory as the .exe.
This fitness evaluation plays 6240 shoes of blackjack for each of the 260 genes.
The search takes 35 hours to complete on a P4 1.8Ghz.
All of the project settings can be modified in main.cpp.

/////////////////////////////////////////////////////////////////////////////

How to use this code to solve a different problem

Write the desired fitness function, add any new settings variables to the ProjectSettings struct
(line 44 StdAfx.h), and modify the initial settings as desired (line 7 main.cpp).  Create a new class
derived from GA_Object, and implement the pure virtual functions InitPopulation, InitGene, and
EvaluateFitness, along with any other virtual functions deemed necessary.

/////////////////////////////////////////////////////////////////////////////

Future work

Future work will involve adding a user interface to manipulate project settings, adding additional
project documentation and code comments, and evolving blackjack play strategies corresponding to
various card counting strategies, most likely with enforced heuristics to enable easier memorization.

/////////////////////////////////////////////////////////////////////////////

Code Documentation

GA_Object.cpp:	

The Genetic Algorithm engine.  Supports various mutation rates, ranked parental selection,
stochastic sampling parental selection, cyclic crossover, crossover at each gene, cloning
the best individual(s) each generation, and creating random individuals each generation.
GA_Object only deals with integer fitness values >= 0.

GAPerson.cpp:

Implementation of an individual, allowing genomes with chromosomes of different length and
each gene to have individually defined allele values.  Has the classes GAPerson, GAChromosome,
and GAGene.  Genes must be initialized separately from initializing an instance of GAPerson.
Populations should not be reused if a new race is defined for a new GA search.

Main.cpp:

Initializes the settings.  Starts the GA search.

StdAfx.h, StdAfx.cpp

These files are used to build a precompiled header (PCH) file
named GABlackjack.pch and a precompiled types file named StdAfx.obj.
StdAfx.h shares headers, macros, and ProjectSettings across all files.

GAOBlackjack.cpp:

Code necessary to run a blackjack GA search.

Blackjackstate.cpp:

Stores the blackjack game state.  Implements all the rules of the game except insurance
and surrender.  Implements two testing procedures.  BTT_STANDARD plays through a defined
number of shoes.  BTT_EACH_GENE plays through 6240 shoes for each gene, dealing the same
two cards to the player and the same up card to the dealer as determined by the current gene.

Cardshell.cpp:

Contains a random number generator, global functions useful for manipulating cards,
and a deck class.

GABlackjack.cpp:

This is the main application source file.

GABlackjack.dsp
    
This file (the project file) contains information at the project level and is used to build
a single project or subproject. Other users can share the project (.dsp) file, but they should
export the makefiles locally.

/////////////////////////////////////////////////////////////////////////////

Structure of the Genome

The genome of each individual has 26 chromosomes of 10 genes each.  The chromosomes correspond
to player hands as follows: 8, 9, 10, 11, 12, 13, 14, 15, 16, A2, A3, A4, A5, A6, A7, A8,
A9, AA, 22, 33, 44, 66, 77, 88, 99, TT.  When the best play is obvious, hands are not
given a chromosome.  Each of the 10 gene positions on a chromosome correspond to the
dealer up cards as follows: 2, 3, 4, 5, 6, 7, 8, 9, T, A.  Each gene is allowed the
allele values: H (hit), S (stand), D (double down).  The last 9 chromosomes involve pairs
and have a 4th allowed allele P (split).
Source: ReadMe.txt, updated 2014-12-09