function [colorData, data] = blackjackTables(version)
% Name: blackjackTables.m
% Organization: Matlab Geeks, under ControlOne, LLC
% Date: September 28, 2013
% Description: This function will be called by our GUI implementation of
%  blackjack basic strategy.  Other versions (strategies) can easily be 
%  added, though similar changes need to be made for drop-down menu in the
%  blackjackGUI.m file.
%
% function [colorData, data] = blackjackTables(version)
% 
% Input:
%  version - default is to provide options for basic strategy
%   if version value is 2, use a randomly chosen combination of
%   'H','S','P','D', or hit, stand, split, double down.  Note that only
%   pairs will have the option of splitting.
%
% Outputs:
%  colorData - blackjack strategy choices using html to create coloring and
%   centering of data
%  data - 'H','S','P','D' cell array of decisions.  Array is 31x10, where
%   the rows are equal to the hand holdings, and the columns are the
%   possible card holdings of the dealer (2:10,A).  The rows are split up
%   into 3 possibilities, 'Hard counts' for values between 5-19, 'Soft
%   counts' for values that include an Ace, and 'Pairs'.
%
% 

if nargin < 1
    version = 1;
end

% create tables for blackjack
% modify versions here if needed.
if version ~= 2
    % create 3 tables for hard counts, soft counts, and pairs
    hardData = [repmat({'H'},1,10);
        {'H'},repmat({'D'},1,4),repmat({'H'},1,5);
        repmat({'D'},1,8),repmat({'H'},1,2);
        repmat({'D'},1,9),{'H'};
        repmat({'H'},1,2),repmat({'S'},1,3),repmat({'H'},1,5);
        repmat([repmat({'S'},1,5),repmat({'H'},1,5)],4,1);
        repmat({'S'},1,10)];
    % soft counts
    softData = [repmat([repmat({'H'},1,3),repmat({'D'},1,2),repmat({'H'},1,5)],2,1);
        repmat([repmat({'H'},1,2),repmat({'D'},1,3),repmat({'H'},1,5)],2,1);
        {'H'},repmat({'D'},1,4),repmat({'H'},1,5);
        {'S'},repmat({'D'},1,4),repmat({'S'},1,2),repmat({'H'},1,3);
        repmat(repmat({'S'},1,10),2,1)];
    % pairs
    pairData = [repmat([repmat({'H'},1,2),repmat({'P'},1,4),repmat({'H'},1,4)],2,1);
        repmat({'H'},1,10);
        repmat({'D'},1,8),repmat({'H'},1,2);
        {'H'},repmat({'P'},1,4),repmat({'H'},1,5);
        repmat({'P'},1,5),repmat({'H'},1,5);
        repmat({'P'},1,10);
        repmat({'P'},1,5),{'S'},repmat({'P'},1,2),repmat({'S'},1,2);
        repmat({'S'},1,10);
        repmat({'P'},1,10)];
    % combine data with blank lines
    data = [repmat({' '},1,10); hardData; 
        repmat({' '},1,10); softData;
        repmat({' '},1,10); pairData];
else
    % random data
    randData = rand(10,10);
    hardData = cell(10,10);
    hardData(randData <= 0.25) = {'S'};
    hardData(randData > 0.25 & randData <= 0.5) = {'H'};
    hardData(randData > 0.5 & randData <= 0.75) = {'P'};
    hardData(randData > 0.75 & randData <= 1) = {'D'};
    % soft counts
    randData = rand(8,10);
    softData = cell(8,10);
    softData(randData <= 0.4) = {'S'};
    softData(randData > 0.4 & randData <= 0.8) = {'H'};
    softData(randData > 0.8 & randData <= 0.9) = {'P'};
    softData(randData > 0.9 & randData <= 1) = {'D'};
    % pairs
    randData = rand(10,10);
    pairData = cell(10,10);
    pairData(randData <= 0.5) = {'S'};
    pairData(randData > 0.5 & randData <= 0.9) = {'H'};
    pairData(randData > 0.9 & randData <= 0.99) = {'P'};
    pairData(randData > 0.99 & randData <= 1) = {'D'};
    
    % combine data with blank lines
    data = [repmat({' '},1,10); hardData; 
        repmat({' '},1,10); softData;
        repmat({' '},1,10); pairData];
end

% find the appropriate values
pIndex = find(ismember(data,'P'));
sIndex = find(ismember(data,'S'));
hIndex = find(ismember(data,'H'));
dIndex = find(ismember(data,'D'));

% apply some colors and centering
% copy over, as will be returning the unchanged data matrix
colorData = data;

% use HTML to style these cells
colorData(pIndex) = strcat('<html><div style="width:35px" align="center"><span style="color: #0000FF; font-weight: bold;">', ...
   colorData(pIndex), '</span></div></html>');

colorData(sIndex) = strcat('<html><div style="width:35px" align="center"><span style="color: #FF0000; font-weight: bold;">', ...
   colorData(sIndex), '</span></div></html>');

colorData(hIndex) = strcat('<html><div style="width:35px" align="center"><span style="color: #008000; font-weight: bold;">', ...
   colorData(hIndex), '</span></div></html>');

colorData(dIndex) = strcat('<html><div style="width:35px" align="center"><span style="color: #FF00FF; font-weight: bold;">', ...
   colorData(dIndex), '</span></div></html>');
