Example #1
0
        private void button2_Click_1(object sender, RoutedEventArgs e)
        {
            BlackJackGameParams blackJackGameParams = new BlackJackGameParams();

            blackJackGameParams.bankroll  = int.Parse(txt_BankRoll.Text);  //  TODO
            blackJackGameParams.betSpread = int.Parse(txt_BetSpread.Text); // Only if not using a betting ramp
            if ((bool)radio_KO.IsChecked)
            {
                blackJackGameParams.countingMethod = CountingMethod.KO; //  TODO: Add Hi-Lo
            }
            else
            {
                blackJackGameParams.countingMethod = CountingMethod.NONE; //  TODO: Add Hi-Lo
            }

            blackJackGameParams.DAS             = (bool)check_DAS.IsChecked; // TODO
            blackJackGameParams.deckPenetration = Double.Parse(txt_Penetration.Text);
            blackJackGameParams.H17             = (bool)check_H17.IsChecked;
            blackJackGameParams.hoursOfPlay     = int.Parse(txt_HoursOfPlay.Text);
            blackJackGameParams.maxBet          = int.Parse(txt_MaxBet.Text);
            blackJackGameParams.minBet          = int.Parse(txt_MinBet.Text);
            blackJackGameParams.numDecks        = int.Parse(txt_DeckCount.Text);
            blackJackGameParams.numPlayers      = int.Parse(txt_NumPlayers.Text);
            blackJackGameParams.RSA             = (bool)check_RSA.IsChecked;       //  TODO
            blackJackGameParams.Surrender       = (bool)check_Surrender.IsChecked; // TODO
            blackJackGameParams.tablePosition   = int.Parse(txt_TablePosition.Text);
            blackJackGameParams.useBetRamp      = (bool)check_BetRamp.IsChecked;

            BasicStrategySimulator bss = new BasicStrategySimulator(blackJackGameParams);

            //TestSuite ts = new TestSuite();
            //ts.test_BSPlayer_playHand(blackJackGameParams, "d:/unittest.test");
            //ts.test_CardCounter(blackJackGameParams);

            bss.BeginSimulation(int.Parse(txt_NumberOfTrials.Text));

            List <Double> bankRollVsGames = bss.getBankRoll_vs_GamesPlayed();
            List <Point>  points          = new List <Point>();

            for (int i = 0; i < bankRollVsGames.Count; i++)
            {
                points.Add(new Point(i, bankRollVsGames[i]));
            }
            EnumerableDataSource <Point> bankrollData = new EnumerableDataSource <Point>(points);

            Func <Point, Point> func = s => new Point(s.X, s.Y);

            myChartPlotter.RemoveUserElements();
            bankrollData.SetXYMapping(func);
            myChartPlotter.MaxWidth  = points.Count;
            myChartPlotter.MaxHeight = bankRollVsGames.Max();
            myChartPlotter.AddLineGraph(bankrollData, Colors.LightBlue, 2, "BankRoll vs Games Played");

            txt_Results.Text = "You made: $" + (bss.getFinalBankrollAverage() - (Double)blackJackGameParams.bankroll).ToString() + "\nAverage Ending Bankroll: $" + bss.getFinalBankrollAverage().ToString() + "\nStd Devation: " + bss.getFinalBankrollStandardDevation().ToString() + "\nBelow Percentage: " + bss.getPercentageBelowAverage().ToString() + "\nAbove Average: " + bss.getPercentageAbove_EqualAverage().ToString() + "\nAverage Below Mean: $" + bss.getAverageOfThoseBelowTheMean().ToString() + "\nAverage Above Mean: $" + bss.getAverageOfThoseAbove_EqualTheMean().ToString();
        }
Example #2
0
 public static int getKeyCount(BlackJackGameParams blackJackGameParams)
 {
     if (blackJackGameParams.countingMethod == CountingMethod.KO)
     {
         return(getCardCountingValueArray_KO()[blackJackGameParams.numDecks].KeyCount);
     }
     else
     {
         return(-1);
     }
 }
Example #3
0
 public int getCount(BlackJackGameParams blackJackGameParams)
 {
     if (blackJackGameParams.countingMethod == CountingMethod.KO)
     {
         return(runningCount);
     }
     else
     {
         return(-1);
     }
 }
Example #4
0
 //  Initializes the class by parsing the CSV file
 public BasicStrategyCalculator(BlackJackGameParams blackJackGameParams)
 {
     //  Mohegan Sun 5$/10$ Table
     //  Check for H17, DAS - Allowed, RSA - Not Allowed, Surrender - Allowed
     //if ((blackJackGameParams.DAS) & (blackJackGameParams.H17) & (!blackJackGameParams.RSA) & (blackJackGameParams.Surrender))
     // {
     //  Found his helpful Code from StackOverflow --  Understand how this works exactly...
     //string path = AppDomain.CurrentDomain.BaseDirectory + "/test.csv";
     ParseCSV("D:/test.csv");
     //  }
 }
Example #5
0
 public static int getIRC(BlackJackGameParams blackJackGameParams)
 {
     if (blackJackGameParams.countingMethod == CountingMethod.KO)
     {
         int IRC = getCardCountingValueArray_KO()[blackJackGameParams.numDecks].IRC;
         return(IRC);
     }
     else
     {
         return(-1);
     }
 }
        //  Initializes the class with the game parameters
        public BasicStrategySimulator(BlackJackGameParams blackJackGameParams)
        {
            this.blackJackGameParams = blackJackGameParams;
            this.cardCounter         = new CardCounting(blackJackGameParams);
            deck    = new Deck(blackJackGameParams.numDecks, Deck.ShuffleType.Durstenfeld, cardCounter);
            players = new List <BSPlayer>();
            dealer  = new BSDealer(blackJackGameParams.H17, deck);

            //  Initialize the players
            for (int i = 0; i < blackJackGameParams.numPlayers; i++)
            {
                BSPlayer newBSPlayer = new BSPlayer(blackJackGameParams);
                players.Add(newBSPlayer);
            }
        }
Example #7
0
        //  Determines the players initial bet, and puts it in the "currentBet" variable
        public void PlaceInitialBet(BlackJackGameParams blackJackGameParams, CardCounting cardCounter)
        {
            if (blackJackGameParams.useBetRamp)
            {
                int betMultiple = cardCounter.calculateBetMultiple();
                initialBet    = betMultiple * blackJackGameParams.minBet;
                currentBet[0] = initialBet;
                BankRoll     -= initialBet;
            }
            else
            {
                //  Code to determine what the player will bet
                if (cardCounter.shouldPlayerBetHigh())
                {
                    Double highBet = blackJackGameParams.minBet * blackJackGameParams.betSpread;
                    if ((BankRoll - highBet) > 0)
                    {
                        initialBet    = highBet;
                        currentBet[0] = highBet;
                        BankRoll     -= highBet;
                    }
                    else
                    {
                        hasQuit = true;
                    }
                }
                else
                {
                    if ((BankRoll - blackJackGameParams.minBet) > 0)
                    {
                        initialBet    = blackJackGameParams.minBet;
                        currentBet[0] = blackJackGameParams.minBet;
                        BankRoll     -= blackJackGameParams.minBet;
                    }
                    else
                    {
                        hasQuit = true;
                    }
                }
            }

            if (currentBet[0] > blackJackGameParams.maxBet)
            {
                throw new Exception("Cannot bet higher than the maximum bet");
            }
        }
        public void test_CardCounter(BlackJackGameParams blackJackGameParams)
        {
            CardCounting cc = new CardCounting(blackJackGameParams);
            Deck         d  = new Deck(1, Deck.ShuffleType.Durstenfeld, cc);

            for (int i = 0; i < 52; i++)
            {
                d.draw();
            }

            if (cc.getCount(blackJackGameParams) == CardCounting.getIRC(blackJackGameParams) + 4)
            {
                System.Diagnostics.Debug.WriteLine("Counting - PASS");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Counting - FAIL");
            }
        }
Example #9
0
 public BSPlayer(BlackJackGameParams blackJackGameParams)
 {
     this.cardList = new List <List <Card> >();
     this.cardList.Add(new List <Card>());
     this.bsc = new BasicStrategyCalculator(blackJackGameParams);
 }
Example #10
0
 public CardCounting(BlackJackGameParams blackJackGameParams)
 {
     this.blackJackGameParams = blackJackGameParams;
     reset();
 }
        public void test_BSPlayer_playHand(BlackJackGameParams blackJackGameParams, string filePath)
        {
            var lines = File.ReadAllLines(filePath).Select(a => a.Split(',', ':'));
            IEnumerator <string[]> iter = lines.GetEnumerator();

            while (1 == 1)
            {
                int         itemCount   = 0;
                List <Card> deckList    = new List <Card>();
                List <Card> playersHand = new List <Card>();
                List <Card> dealersHand = new List <Card>();
                Double      initialBet  = 0;
                Double      winnings    = 0;
                string      name        = "";
                while (iter.MoveNext() & (itemCount < 5))
                {
                    var l = iter.Current;
                    switch (l[0])
                    {
                    case "Name":
                        name = l[1];
                        break;

                    case "Player":
                        for (int i = 1; i < l.Length; i++)
                        {
                            l[i].Replace(" ", "");
                            playersHand.Add(getCardFromText(l[i]));
                        }
                        itemCount += 1;
                        break;

                    case "Dealer":
                        for (int i = 1; i < l.Length; i++)
                        {
                            l[i].Replace(" ", "");
                            dealersHand.Add(getCardFromText(l[i]));
                        }
                        itemCount += 1;
                        break;

                    case "Deck":
                        for (int i = 1; i < l.Length; i++)
                        {
                            l[i].Replace(" ", "");
                            deckList.Add(getCardFromText(l[i]));
                        }
                        itemCount += 1;
                        break;

                    case "Initial":
                        l[1].Replace(" ", "");
                        initialBet = Double.Parse(l[1]);
                        itemCount += 1;
                        break;

                    case "Win":
                        l[1].Replace(" ", "");
                        winnings   = Double.Parse(l[1]);
                        itemCount += 1;
                        break;

                    default:
                        break;
                    }
                }

                //  When the iterator has run out of new items then return
                if (!(itemCount == 5))
                {
                    return;
                }
                BSPlayer  player = new BSPlayer(blackJackGameParams);
                DeckDummy deck   = new DeckDummy();
                BSDealer  dealer = new BSDealer(false, deck);

                deck.setCardList(deckList);

                dealer.setHand(dealersHand);

                player.clearCurrentBets();
                player.clearHand();
                player.setBankRoll(blackJackGameParams.bankroll);
                player.setInitialBet(initialBet);
                player.setFirstHand(playersHand);

                player.playHand(dealer, new CardCounting(blackJackGameParams));
                BasicStrategySimulator.processPlayerWinnings(player, dealer);
                if (player.getTotalHandWinnings() == winnings)
                {
                    System.Diagnostics.Debug.WriteLine(name + ": PASS");
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine(name + ": FAIL");
                }
            }
        }