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();
        }
        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");
                }
            }
        }