SetDirectory["/home/campus03/struther/Desktop/Link to Courses/2990/GamblerRuns"]

Basic Organization

This could be expanded a lot ...

Each hand stores a list of cards, a wager on that hand, and a tag.

The tag signifies if action can still be taken on the hand: 1 for acion possible, 0 for no action possible (either because it is >21 or if a betting decision requires the player to stop)

eg. Hand = {{cards}, wager, tag} = {{1, 2, 13}, 12, 1}  denotes a hand cosnsiting of a {Ace, 2,King} with a 12 dollar wager

Card counting is included in the function “Deal” that deals new cards.

Deal takes in and returns a Hand, a Shoe, a Stack, and a Count.

The basic strategy function takes in a Hand with a Dealer card.  It returns one of the following strings.

“H”, “S”,”SP”,”DH”, “SU”, “DS”

described in the wiki page.

Basic  Functions

Card Counting and Wager[Count] Functions

(*Wager[count_]:=Module[{},
Which[
count[[1]]>0,10,
True,1]]*)

Wager[count_]:=1

InitializeCount[]:= {0,0};
UpdateCount[count_, card_]:= count

(*(*hi low count *)
InitializeCount[]:= {0,0};
UpdateCount[count_, card_]:= Switch[Min[card,10],
1,count+{-1,1},
10,count+{-1,0},
2,count+{1,0},
3,count+{1,0},
4,count+{1,0},
5,count+{1,0},
6,count+{1,0},
_, count]

(**)

(*Zen count*)
InitializeCount[]:= {0,0};
UpdateCount[count_, card_]:= Switch[Min[card,10],
1,count+{-1,1},
10,count+{-2,0},
2,count+{1,0},
3,count+{1,0},
4,count+{2,0},
5,count+{2,0},
6,count+{2,0},
7,count+{1,0},
_, count]

*)

(*

(*Revere RAPC count*)
InitializeCount[]:= {0,0};
UpdateCount[count_, card_]:= Switch[Min[card,10],
1,count+{-4,1},
10,count+{-3,0},
2,count+{2,0},
3,count+{3,0},
4,count+{3,0},
5,count+{4,0},
6,count+{3,0},
7,count+{2,0},
9,count+{-1,0},
_, count]

*)

count=InitializeCount[];
count=UpdateCount[count,12]
count=UpdateCount[count,1]
count=UpdateCount[count,2]

New Deck Function

Shuffles a new Shoe of cards up out of a specified numerb of standard decks.

NewShoe[numberofdecks_]:=RandomSample[Flatten[Table[i,{i,1,13},{4},{numberofdecks}],2]]

NewShoe[2]

Deal Function and Shuffle Barrier

ShuffleBarrier is the point when the Dealer reshuffles the deck. It reads in a Hand, a shoe, and a count and updates them all. In the real world we do not see the dealer card untill the end.

Deal[{Hand_,shoe_,count_}, numberofdecks_]:=Module[
{ShuffleBarrier=40,TempNewShoe=shoe,TempNewCount=count,TempNewHand=Hand,Card},
If[Length[shoe]<ShuffleBarrier,
TempNewShoe=NewShoe[numberofdecks]; TempNewCount=InitializeCount[]
];
Card=TempNewShoe[[-1]];
TempNewShoe=Drop[TempNewShoe,-1];
TempNewCount=UpdateCount[TempNewCount, Card];
AppendTo[TempNewHand,Card];
{TempNewHand,TempNewShoe,TempNewCount}
]

NumberOfShoes=2;
shoe=NewShoe[NumberOfShoes];
count=InitializeCount[];
Hand={1,4};
Do[
{Hand,shoe,count}=Deal[{Hand,shoe,count},NumberOfShoes],
{5}]
{Hand,shoe,count}

Hand Scoring Functions: ScoreHand, IsPair, IsBlackJack

Takes in a hand (list of cards) counts the number of aces and computes the highest possible score  less than or equal to 21.  It returns the best score and a flag if the the best score is hard or soft.

ScoreHand[HandIn_]:= Module[
{n,Hand=HandIn,AceCount,BaseScore,Score},
(* Replaces face cards with 10s *)
Hand=Hand/.{11->10,12->10,13->10};
(* Counts Aces *)
AceCount=Count[Hand,1];
(* Base Score Counts all Aces as 1 *)
BaseScore=Sum[Hand[[n]],{n,1,Length[Hand]}];
(* Computes the largest of the possible scores that is 21 or less *)
Score=Max[Max[Select[BaseScore+10*Range[0, AceCount],#<=21&]],0];
{Score,If[BaseScore==Score,"Hard","Soft"]}
]

I think this works, but note what this does if you bust!

ScoreHand[{1,1,1,1,2}]
ScoreHand[{1,1,1,1,13,4}]
ScoreHand[{1,1,1,1,13,8}]
ScoreHand[{13,4,8}]

The basic strategy has some special options for splitting pairs. The following checks for a pair. According to the wiki page some casinos allow you to split {11,12} and some do not.

IsPair[Hand_]:=And[Length[Hand]==2,Hand[[1]]==Hand[[2]]]

Hand={12,11};
IsPair[Hand]

IsBlackJack[Hand_]:=Module[{},
Boole[ScoreHand[Hand][[1]]==21&&Length[Hand]==2]]

IsBlackJack[{1,10}]
IsBlackJack[{1,9}]
IsBlackJack[{2,9,10}]

Player Decision Functions And Decision Tables: Hard, Soft, Pairs

Implements the basic strategy as described on the wiki page 
  http://en.wikipedia.org/wiki/Blackjack#Basic_strategy.
The strategy is described in three tables: hard, soft, and pairs.

The first thing to make is a splitter.

PlayerDecision[Hand_,DealerCard_]:= Module[
{Score,Flag,Play},
{Score,Flag}=ScoreHand[Hand];
Which[
IsPair[Hand],    Play=PairsFunction[Hand,DealerCard],
Flag=="Soft",  Play=SoftFunction[{Score,Flag}, DealerCard],
Flag=="Hard",  Play=HardFunction[{Score,Flag}, DealerCard]
];
Play
]

The second thing to do is make the three functions up above.

Pairs Function

Clear[PairsFunction]
PairsFunction[Hand_, DealerCard_]:= Module[
{PairsTable,Card},
PairsTable=(({{"SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP"}, {"H", "SP", "SP", "SP", "SP", "SP", "SP", "H", "H", "H"}, {"H", "SP", "SP", "SP", "SP", "SP", "SP", "H", "H", "H"}, {"H", "H", "H", "H", "SP", "SP", "H", "H", "H", "H"}, {"H", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "H"}, {"H", "SP", "SP", "SP", "SP", "SP", "H", "H", "H", "H"}, {"H", "SP", "SP", "SP", "SP", "SP", "SP", "H", "H", "H"}, {"SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP", "SP"}, {"S", "SP", "SP", "SP", "SP", "SP", "S", "SP", "SP", "S"}, {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}}));
Card=Hand[[1]]/.{11->10,12->10,13->10};
PairsTable[[Card,DealerCard/.{11->10,12->10,13->10}]]
]

Checking if this is correct.

TableForm[
Table[ PairsFunction[{i,i},d],
{i,1,13},{d,1,13}],
TableHeadings->{
{"A-A","2-2","3-3","4-4","5-5","6-6","7-7","8-8","9-9","10-10","11-11","12-12","13-13"},Automatic}
]

Soft Function

For consistency I added a row for 21 to this table.

SoftFunction[{Score_,Flag_},DealerCard_]:=Module[
{SoftTable},
SoftTable=(({{"H", "H", "H", "H", "DH", "DH", "H", "H", "H", "H"}, {"H", "H", "H", "H", "DH", "DH", "H", "H", "H", "H"}, {"H", "H", "H", "DH", "DH", "DH", "H", "H", "H", "H"}, {"H", "H", "H", "DH", "DH", "DH", "H", "H", "H", "H"}, {"H", "H", "DH", "DH", "DH", "DH", "H", "H", "H", "H"}, {"H", "S", "DS", "DS", "DS", "DS", "S", "S", "H", "H"}, {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}, {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}, {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}, {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}}));
SoftTable[[Score-11,DealerCard/.{11->10,12->10,13->10}]]
]

Checking

TableForm[
Table[ SoftFunction[{SoftTotal,"Soft"},d],
{SoftTotal,13,21},{d,1,13}],
TableHeadings->{{"A2","A3","A4","A5","A6","A7","A8","A9","A10"},Automatic}
]

SoftFunction[{20,"Soft"},1]

Hard Function

For consistency I added a row for 21 to this table.

HardFunction[{Score_,Flag_},DealerCard_]:=Module[
{HardTable},
HardTable=(({{"H", "H", "H", "H", "H", "H", "H", "H", "H", "H"}, {"H", "H", "H", "H", "H", "H", "H", "H", "H", "H"}, {"H", "H", "H", "H", "H", "H", "H", "H", "H", "H"}, {"H", "H", "H", "H", "H", "H", "H", "H", "H", "H"}, {"H", "H", "DH", "DH", "DH", "DH", "H", "H", "H", "H"}, {"H", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "H"}, {"H", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "DH", "DH"}, {"H", "H", "H", "S", "S", "S", "H", "H", "H", "H"}, {"H", "S", "S", "S", "S", "S", "H", "H", "H", "H"}, {"H", "S", "S", "S", "S", "S", "H", "H", "H", "H"}, {"H", "S", "S", "S", "S", "S", "H", "H", "H", "SU"}, {"SU", "S", "S", "S", "S", "S", "H", "H", "SU", "SU"}, {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}, {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}, {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}, {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}, {"S", "S", "S", "S", "S", "S", "S", "S", "S", "S"}}));
HardTable[[Score-4,DealerCard/.{11->10,12->10,13->10}]]
]

Checking

TableForm[
Table[ HardFunction[{HardTotal,"hard"},d],
{HardTotal,5,21},{d,1,13}],
TableHeadings->{Range[5,21],Automatic}
]

Testing Basic Strategy

Check this.  Is the thing below really correct.

Hand={10,1};
DealerCard=3;
BasicStrategySplitter[Hand,DealerCard]

Hand={10,6};
DealerCard=1;
BasicStrategySplitter[Hand,DealerCard]

Hand={6,6};
DealerCard=3;
BasicStrategySplitter[Hand,DealerCard]

Game Play Functions

Player Action Function

It needs to do the following
({{"H", Hit, Adds a card to the hand}, {"DH", Double or Hit, Adds a card, adjusts bet, announces done.}, {"DS", Double or Stay, DH if two cards, Stay if more }, {"SU", Surrender, Gives up the hand adjusts bet}, {"SP", Split, Splits the hand and deals, adjusts bets.}})
({{"S", Stay, Announces done}})

(* "Hands" is a list of hands where each hand is "hand"={list of cards, CurrentWager on hand, Tag}, 
	tag is 0 for no further action allowed/required on hand, else 1*)

Clear[PlayerAction]; PlayerAction[{Hands_, currentdeck_, currentcount_, dealercard_, numberofdecks_}] := Module[
  {CurrentDeck = currentdeck, CurrentCount = currentcount, DealerCard = dealercard, NumberOfDecks = numberofdecks, NewHand1, NewHand2, NewDeck, NewCount, NewWager, NewStack, NewTag , Hand, CurrentWager, Tag, NewHands = {},playerdecision},
  
  (*hand={Hand_,CurrentWager_,Tag_}*)
  Do[
   {Hand, CurrentWager, Tag} = Hands[[i]]; NewHand2 = {}; If[ScoreHand[Hand][[1]] == 0(*for bust*), NewTag = 0];
   
   If[Tag == 1, playerdecision = PlayerDecision[Hand, DealerCard];
    Switch[playerdecision,
     "H", {NewHand1, NewDeck, NewCount} = Deal[{Hand, CurrentDeck, CurrentCount}, NumberOfDecks];
     	NewWager = CurrentWager; NewTag = 1,
     
     "S", {NewHand1, NewDeck, NewCount} = {Hand, CurrentDeck, CurrentCount};  
     	NewWager = CurrentWager; NewTag = 0,
     
     "DH", {NewHand1, NewDeck, NewCount} = Deal[{Hand, CurrentDeck, CurrentCount}, NumberOfDecks];
     	Switch[Length[Hand],
      	2, NewWager = 2*CurrentWager; NewTag = 0,
      	_, NewWager = CurrentWager; NewTag = 1],
     	  
     "DS", Switch[Length[Hand],
      	2, {NewHand1, NewDeck, NewCount} = Deal[{Hand, CurrentDeck, CurrentCount}, NumberOfDecks];
      		NewWager = 2*CurrentWager; NewTag = 0,
      	_, {NewHand1, NewDeck, NewCount} = {Hand, CurrentDeck, CurrentCount};
      		NewWager = CurrentWager; NewTag = 0],
     
     "SU", {NewHand1, NewDeck, NewCount} = {{0, 0}, CurrentDeck, CurrentCount};
     	NewWager = .5*CurrentWager; NewTag = 0,
     
     "SP", {NewHand1, NewDeck, NewCount} = Deal[{{Hand[[1]]}, CurrentDeck, CurrentCount}, NumberOfDecks];
     	   {NewHand2, NewDeck, NewCount} = Deal[{{Hand[[1]]}, NewDeck, NewCount}, NumberOfDecks];
     	NewWager = CurrentWager; NewTag = 1
     ];(*end switch*)
    If[ScoreHand[NewHand1][[1]] == 0(*for bust*), NewTag = 0];
    
    {Hand, CurrentWager, Tag} = {NewHand1, NewWager, NewTag};
    {CurrentDeck, CurrentCount} = {NewDeck, NewCount} ; 
    ];(*end if*)
   AppendTo[NewHands, {Hand, CurrentWager, Tag}]; 
   If[NewHand2 != {}, AppendTo[NewHands, {NewHand2, NewWager, NewTag}]];
   , {i, 1, Length[Hands]}];(*end do*)
  
  
  {NewHands, CurrentDeck, CurrentCount, dealercard, numberofdecks}
  ]

Test Split Works Finally!!!

shoe = NewShoe[2];
{dealerhand, playerhand, deck} = {(*shoe[[1;;2]],shoe[[3;;4]],shoe[[5;;Length[shoe]]]*){3}, {7, 7}, {4, 4, 7, 11, 10, 11, 5, 6, 6, 7, 10, 5, 8, 13, 13, 2, 4, 12, 3, 2, 4, 5, 10, 10, 8, 13, 13, 12, 1, 13, 2, 2, 3, 9, 11, 8, 9, 1, 7, 7, 5, 2, 9, 8, 9, 3, 5, 11, 1, 12, 11, 7, 3, 10, 12, 9, 11, 5, 9, 13, 3, 13, 9, 2, 8, 6, 5, 3, 12, 7, 9, 11, 13, 10, 8, 1, 11, 12, 10, 4, 1, 8, 2, 8, 1, 6, 7, 10, 1, 3, 4, 4, 6, 4, 12, 5, 5, 2, 7, 12}}; dealercard = dealerhand[[1]];
{stack, wager, tag, count, numberofdecks} = {500, 10, 1, {0, 0}, 2};
dealercard
{{{playerhand, wager, tag}}, deck, count, dealercard, numberofdecks}

PlayerAction[{{{playerhand, wager, tag}}, deck, count, dealercard, numberofdecks}]
PlayerAction[%]
PlayerAction[%]
PlayerAction[%]

Dealer Action Function

DealerAction[{dealerhand_,tag_,currentdeck_,currentcount_,numberofdecks_}]:=Module[
{Deck=currentdeck,Count=currentcount,Tag=tag,Hand=dealerhand},
If[ScoreHand[dealerhand][[1]]==0,Tag=0];If[Tag==1,
If[ScoreHand[Hand][[1]]<17||(ScoreHand[Hand][[1]]==17&&ScoreHand[Hand][[2]]=="Soft"),
{Hand,Deck,Count}=Deal[{Hand,Deck,Count},numberofdecks],
Tag=0];
If[ScoreHand[Hand][[1]]==0,Tag=0]];{Hand,Tag,Deck,Count,numberofdecks}]

deck=NewShoe[2];dealerhand=NewShoe[1][[1;;2]];
{dealerhand,1,deck,{0,0},2}
DealerAction[%]
DealerAction[%]
DealerAction[%]

Play Cards Function

PlayCards[currentcount_,deck_,numberofdecks_]:=Module[
{CurrentCount=currentcount,Deck=deck,Cards={},Playerhands,Dealerhand,Tag,FinalPlayerHands,FinalDealerHand,NumberOfDecks,DealerCard},

Do[{Cards,Deck,CurrentCount}=Deal[{Cards,Deck,CurrentCount},numberofdecks],{4}];
Playerhands={{Cards[[1;;2]],Wager[currentcount],1}};
Dealerhand=Cards[[3;;4]];
Tag=1;

{FinalDealerHand,Tag,Deck,CurrentCount,NumberOfDecks}=
NestWhile[DealerAction,{Dealerhand,Tag,Deck,CurrentCount,numberofdecks},#[[2]]>0&(*until the tag is 0*),1,200];
{FinalPlayerHands,Deck,CurrentCount,DealerCard,NumberOfDecks}=
NestWhile[PlayerAction,{Playerhands,Deck,CurrentCount,Dealerhand[[1]],numberofdecks},Sum[#[[1]][[i]][[3]],{i,1,Length[Playerhands]}]>0&(*until all the tags are 0*),1,200];

{FinalPlayerHands,FinalDealerHand,CurrentCount,Deck}
]

Test Nest While Player Action

shoe=NewShoe[2];
{dealercard,playerhand,deck}={shoe[[1]],shoe[[3;;4]],shoe[[5;;Length[shoe]]]};
{stack,wager,tag,count,numberofdecks}={500,10,1,{0,0},2};Playerhands={{playerhand,wager,tag}};
dealercard

NestWhile[PlayerAction,{Playerhands,deck,count,dealercard,numberofdecks},Sum[#[[1]][[i]][[3]],{i,1,Length[Playerhands]}]>0&(*all of the tags are 0*),1,200]

Test Player Round Function

PlayCards[{0,0},Join[NewShoe[1],{6,6,6,6}],2]

Chip Pusher Function

ChipPusher[stack_,{PlayerHands_,DealerHand_,CurrentCount_,Deck_}]:=Module[
{PlayerHandsScores,PlayerHandsWagers,DealerHandScore,Stack=stack},

PlayerHandsScores=Table[ScoreHand[PlayerHands[[i]][[1]]][[1]],{i,1,Length[PlayerHands]}];
PlayerHandsWagers=Table[PlayerHands[[i]][[2]],{i,1,Length[PlayerHands]}];
DealerHandScore=ScoreHand[DealerHand][[1]];
Do[
Which[
PlayerHandsScores[[i]]<DealerHandScore,Stack=Stack-PlayerHandsWagers[[i]],
IsBlackJack[PlayerHands[[i]][[1]]]>IsBlackJack[DealerHand],Stack=Stack+1.5*PlayerHandsWagers[[i]],(* 3:2 payout for BlackJack*)
PlayerHandsScores[[i]]>DealerHandScore,Stack=Stack+PlayerHandsWagers[[i]],
PlayerHandsScores[[i]]==0,Stack=Stack-PlayerHandsWagers[[i]],(*for player and dealer bust*)
PlayerHandsScores[[i]]==DealerHandScore,Stack=Stack]
,{i,1,Length[PlayerHands]}];
Stack
]

Clear[CurrentCount,Deck]
stack=100;DealerHand={1,9};PlayerHands={{{1,10},10,0},{{1,8},10,0}};
ChipPusher[stack,{PlayerHands,DealerHand,CurrentCount,Deck}]

stack=100;DealerHand={10,1};PlayerHands={{{10,1},10,0}};
ChipPusher[stack,{PlayerHands,DealerHand,CurrentCount,Deck}]

Play Bets Function

PlayBets[{stack_,currentcount_,deck_,numberofdecks_}]:=Module[{PlayerHands,DealerHand,CurrentCount,Deck,Stack},

{PlayerHands,DealerHand,CurrentCount,Deck}=PlayCards[currentcount,deck,numberofdecks];
Stack=ChipPusher[stack,{PlayerHands,DealerHand,CurrentCount,Deck}];

{Stack,CurrentCount,Deck,numberofdecks}]

PlayBets[{100,{5,0},NewShoe[1],1}]

Repetitive Play

Functions

IncomeAtGameEnd[StackData_,InitialStack_]:=Module[{},
Table[StackData[[i]][[-1]]-InitialStack,{i,1,Length[StackData]}]
]

IncomePerHand[StackData_,InitialStack_]:=Module[{},
Sum[StackData[[i]][[-1]]-InitialStack,{i,1,Length[StackData]}]/Sum[Length[StackData[[i]]],{i,1,Length[StackData]}]
]

WinProbabilityOfCount[StackData_,CountData_]:=Module[{StackChange,CountOfI,StackOfCount={},UnderNeg25,Over25},
StackChange= 
Flatten[
Table[{StackData[[j]][[i+1]]-StackData[[j]][[i]],CountData[[j]][[i]]},{j,1,Length[StackData]},{i, 1,Length[StackData[[j]]]-1}],
1];(*List of {StackChange, count}*)

Do[
CountOfI=Select[StackChange,#[[2]]==i&];
If[Length[CountOfI]>0,
AppendTo[StackOfCount,{i,((Sum[CountOfI[[j]][[1]],{j,1,Length[CountOfI]}])/(Length[CountOfI])),Length[CountOfI]}]]
,{i,-25,25}];


CountOfI=Select[StackChange,#[[2]]<-25&];
If[Length[CountOfI]>0,
UnderNeg25={{"<-25",((Sum[CountOfI[[j]][[1]],{j,1,Length[CountOfI]}])/(Length[CountOfI])),Length[CountOfI]}}];

CountOfI=Select[StackChange,#[[2]]>25&];
If[Length[CountOfI]>0,
Over25={{">25",((Sum[CountOfI[[j]][[1]],{j,1,Length[CountOfI]}])/(Length[CountOfI])),Length[CountOfI]}}];


Join[UnderNeg25,Sort[StackOfCount],Over25]
]

Data Collection

InitialStack:=100
DecksPerShoe:=2
MinStack:=0
MaxStack:=2InitialStack
MaxHandsPerGame:=1*^5

GamesPerFile:=100(*500*)
FileString:="21TwoDecks``.txt"
ExportFileRange:={1,10000}
ImportFileRange:={1,100}

Table[
BetData=Table[NestWhileList[PlayBets,{InitialStack,InitializeCount[],NewShoe[DecksPerShoe],DecksPerShoe},MinStack<#[[1]]<MaxStack&,1,MaxHandsPerGame],{GamesPerFile}];
Export[ToString[StringForm[FileString,i]],ToString[BetData[[All,All,1;;2]]]]
,{i,ExportFileRange[[1]],ExportFileRange[[2]]}];

(*JoinedData=Table[ToExpression[Import[ToString[StringForm[FileString,i]]]],{i,ImportFileRange[[1]],ImportFileRange[[2]]}];*)

(*StackData=Flatten[Table[JoinedData[[k]][[j]][[i]][[1]],{k,ImportFileRange[[1]],ImportFileRange[[2]]},{j,1,Length[JoinedData[[k]]]},{i,1,Length[JoinedData[[k]][[j]]]}],1];
CountData=Flatten[Table[JoinedData[[k]][[j]][[i]][[2]][[1]],{k,ImportFileRange[[1]],ImportFileRange[[2]]},{j,1,Length[JoinedData[[k]]]},{i,1,Length[JoinedData[[k]][[j]]]}],1];*)

(*{ListLinePlot[StackData[[1;;6]],AxesLabel->{"Hands Played","Stack"}],ListLinePlot[StackData[[1]],AxesLabel->{"Hands Played","Stack"}]}
{ListLinePlot[CountData[[1;;6]],AxesLabel->{"Hands Played","Count"}],ListLinePlot[CountData[[1]],AxesLabel->{"Hands Played","Count"}]}
*)

(*IncomePerHandList={};
Do[
JoinedData=ToExpression[Import[ToString[StringForm[FileString,k]]]];
StackData=Table[JoinedData[[j]][[i]][[1]],{j,1,Length[JoinedData]},{i,1,Length[JoinedData[[j]]]}];
Do[
AppendTo[IncomePerHandList,StackData[[b]][[a+1]]-StackData[[b]][[a]]],
{b,1,Length[StackData]},{a,1,Length[StackData[[b]]]-1}
],(*list of {net gain in game,number of hands} *)
{k,1,1}]
IncomePerHandList;*)

(*Length[IncomePerHandList]

SampleMean=Mean[IncomePerHandList]
StandardError=((StandardDeviation[IncomePerHandList])/(Sqrt[Length[IncomePerHandList]]))*)

(*Clear[MeanData]
MeanData[n_]:=Table[
SampleData=RandomSample[IncomePerHandList,10000];
Mean[SampleData],
{n}]

Histogram[MeanData[10000],
Automatic,
"Probability"]*)

(*Histogram[IncomeAtGameEnd[StackData,InitialStack],{{-200,-140,-130,-120,-110,-100,-99,100,101,110,120,130,140,200}},{"Log","Count"}]*)

(*CombinedData=WinProbabilityOfCount[StackData,CountData];*)

(*(*This is the average net income per hand played corresponding to a specific count*)
BarChart[Table[CombinedData[[i]][[2]],{i,1,Length[CombinedData]}],ChartLabels->Table[CombinedData[[i]][[1]],{i,1,Length[CombinedData]}],AxesLabel->{"Count","Win/Lose"}]

(*This is the number of data points in each bin of the above plot*)
BarChart[Table[CombinedData[[i]][[3]],{i,1,Length[CombinedData]}],ChartLabels->Table[CombinedData[[i]][[1]],{i,1,Length[CombinedData]}],AxesLabel->{"Count","Win/Lose - Number Per Bin"},ScalingFunctions->{"Log"}]*)