Пример #1
0
		public bool AddCard( Card c )
		{
			//find next empty spot
			int pos = 0;
			while ( Cards[pos].Value > 0 && pos < Cards.Length )
				pos++;

			if ( pos >= Cards.Length )
				return false;

			Cards[pos].Value = c.Value;
			Cards[pos].Suit = c.Suit;

			return true;
		}
Пример #2
0
		public NewDeck()
		{
			int index=0;
			Cards = new Card[52];
			for ( int z=0; z<52; z++ )
				Cards[z] = new Card();

			for ( int i=0; i<4; i++ )//Suits
			{
				for ( int j=1; j<14; j++ )//Values
				{
					Cards[index].Suit = i;
					if ( j == 1 )
						Cards[index].Value = 11;
					else if ( j > 10 )
						Cards[index].Value = 10;
					else
						Cards[index].Value = j;
					index++;
				}
			}
		}
Пример #3
0
        private void Betting(float Cash, ref float Bet, float originalBet,
            bool trend, ref bool stayBet, int movement, Card[] Cards, int deckIndex)
        {
            bool changeBet = System.Convert.ToBoolean(chkChangeBet.Checked);

            if (!changeBet)
                return;

            int increaseA = System.Convert.ToInt32(txtIncreaseBet.Text);
            int decreaseA = System.Convert.ToInt32(txtDecreaseBet.Text);
            double increaseBy = System.Convert.ToDouble(txtIncreaseBy.Text);
            bool factor = radFactor.Checked;
            bool amount = radAmount.Checked;
            bool special = chkSpecial.Checked;
            int maxBet = System.Convert.ToInt32(txtMaxBet.Text);

            if (special)
            {
                if (stayBet == true)
                    Bet = Bet;
                else if (trend == false)
                {
                    if (factor)
                        Bet = Bet * (float)increaseBy;
                    else//amount
                        Bet += (float)increaseBy;
                }
                else if (trend == true)
                    Bet = originalBet;
            }
            else
            {
                if (stayBet == true)
                    Bet = Bet;
                else if (movement <= (-increaseA))
                {
                    if (factor)
                        Bet = Bet * (float)increaseBy;
                    else//amount
                        Bet += (float)increaseBy;
                }
                else if (movement >= decreaseA)
                    Bet = originalBet;
            }

            stayBet = false;

            //Card-Counting betting
            //			int decksLeft = (Cards.Length - deckIndex) / 52;
            //			int trueCount = cardCountValue / decksLeft;
            //			if ( trueCount > 5 )
            //				Bet = originalBet*4;
            //			else if ( trueCount > 3 )
            //				Bet = originalBet*3;
            //			else if ( trueCount > 1 )
            //				Bet = originalBet*2;
            //			else
            //				Bet = originalBet;

            if (Bet > maxBet)
                Bet = maxBet;

            if (Bet > Cash)
                Bet = Cash;//toss it all in!
        }
Пример #4
0
        private void btnOdds_Click(object sender, System.EventArgs e)
        {
            BJResults Results = new BJResults();

            float startingCash = 99999f;
            float bet = 10f;
            int index = 0;
            bool trend = true;
            bool stayBet = false;
            
            
            // prepare the shoe
            int numDecks = 5;
            int totalCards = numDecks * 52;
            Card[] deck = new Card[totalCards];
            for (int i = 0; i < totalCards; i++)
                deck[i] = new Card();

            float totalCash = startingCash;
            for (int i = 0; i < 2000; i++)//many many times
            {
                index = 0;
                float cash = startingCash;
                totalCash -= cash;

                Shuffle(ref deck, numDecks);

                while (index < (numDecks * 52) - 60) //leave a few cards
                {
                    PlayHand(ref cash, ref bet, 10, trend, ref stayBet, ref Results, deck, ref index, 1, 2, false);
                }

                totalCash += cash;
            }

            lblOddsGames.Text = "2000 decks played";

            DisplayOdds(Results, totalCash - startingCash);
        }
Пример #5
0
        private void PlayBigDeck(ref Card[] Cards, ref float Cash, float startingCash,
            ref BJResults Results, StreamWriter csvWriter)
        {
            float bet = System.Convert.ToInt32(txtStartingBet.Text, 10);
            float originalBet = bet;
            float originalCash = Cash;
            int maxPlayers = System.Convert.ToInt32(txtPlayers.Text, 10);
            int mySeat = System.Convert.ToInt32(txtSeatingPos.Text, 10);
            bool quitWhenAhead = chkQuitWhenAhead.Checked;
            double percentGains = System.Convert.ToDouble(txtPercentGains.Text);
            percentGains = (percentGains + 100) / 100;
            int index = 0;//card index
            bool trend = true;//MattLee Special (21) trend
            bool stayBet = false;//for pushes
            bool doubled = false;//keep track if we doubled-down

            int iMinShoeSize = 52 * 2;
            while (index < Cards.Length - iMinShoeSize && Cash > 0)//leave 2 decks unplayed
            {
                if (quitWhenAhead)
                {
                    if (Cash >= startingCash * percentGains)
                        break;
                }
                //csvWriter.WriteLine("{0}, {1}", Cash, bet);
                csvWriter.WriteLine("{0}, {1}, {2}", Cash, bet, lifeTimeCash);

                PlayHand(ref Cash, ref bet, originalBet, trend, ref stayBet, ref Results, Cards, ref index, mySeat, maxPlayers, doubled);
            }
        }
Пример #6
0
        private void PlayHand(ref float Cash, ref float bet, float originalBet, bool trend,
                    ref bool stayBet, ref BJResults Results, Card[] Cards, ref int index,
                    int mySeat, int maxPlayers, bool doubled)
        {
            CardHand dealerHand = new CardHand(15);
            CardHand myHand = new CardHand(15);

            Betting(Cash, ref bet, originalBet, trend,
                ref stayBet, Results.movement, Cards, index);

            InitialDeal(ref Cards, ref index, ref myHand, ref dealerHand,
                mySeat, maxPlayers);

            if (ThereIsABlackJack(myHand, dealerHand, ref Cash, bet,
                ref Results, ref trend))
            {
                return;
            }

            //double-down?
            if (chkDoubleDown.Checked)
            {
                if ((dealerHand.Showing == 4 || dealerHand.Showing == 5 ||
                    dealerHand.Showing == 6) && (myHand.Total == 10 ||
                    myHand.Total == 11))
                {
                    if (Cash > bet * 2)
                    {
                        bet = bet * 2;
                        doubled = true;
                    }
                }
            }

            HitStayBust(ref Cards, ref index, ref myHand, ref dealerHand,
                maxPlayers, mySeat, doubled);

            WrapUp(myHand, dealerHand, ref Cash, bet, ref Results);

            if (doubled)
            {
                bet /= 2;
                doubled = false;
            }
        }
Пример #7
0
        private void Shuffle(ref Card[] Cards, int Decks)
        {
            cardCountValue = 0;
            int index = 0;
            for (int i = 0; i < Decks; i++)
            {
                NewDeck freshie = new NewDeck();

                for (int j = 0; j < 52; j++)
                {
                    Random rand = new Random();

                    //Find an undealt card and assign it to the BlackJack deck
                    int pos = rand.Next(0, 51);
                    while (freshie.Cards[pos].Dealt)
                    {
                        pos = rand.Next(0, 51);
                        if (j == 51)
                            pos = 51;
                    }
                    Cards[index].Value = freshie.Cards[pos].Value;
                    Cards[index].Suit = freshie.Cards[pos].Suit;
                    Cards[index].Dealt = false;
                    freshie.Cards[pos].Dealt = true;

                    index++;
                }
            }
        }
Пример #8
0
        private void btnPlay_Click(object sender, System.EventArgs e)
        {
            string path = Path.Combine(System.Environment.CurrentDirectory, "data.csv");
            System.IO.StreamWriter csvWriter = System.IO.File.CreateText(path);

            float cash = System.Convert.ToInt32(txtCash.Text, 10);
            BJResults results = new BJResults();
            results.minCash = results.maxCash = cash;
            int totalGames = 0;
            int iTotalCount = 1;
            float totalCash = 0;
            Int32.TryParse(txtPlayCount.Text, out iTotalCount);
            for (int playCount = 0; playCount < iTotalCount; playCount++)
            {
                // prepare strategy
                int games = 0;
                cash = System.Convert.ToInt32(txtCash.Text, 10);
                float startingCash = cash;
                int maxGames = System.Convert.ToInt32(txtRoundsPlayed.Text, 10);
                int decks = System.Convert.ToInt32(txtDecks.Text, 10);
                bool quitWhenAhead = chkQuitWhenAhead.Checked;
                double percentGains = System.Convert.ToDouble(txtPercentGains.Text);
                percentGains = (percentGains + 100) / 100;

                // prepare the shoe
                int totalCards = decks * 52;
                Card[] Cards = new Card[totalCards];
                for (int i = 0; i < totalCards; i++)
                    Cards[i] = new Card();

                csvWriter.WriteLine("----New Play----");
                csvWriter.WriteLine("Cash, Bet");

                lifeTimeCash -= cash;
                totalCash -= cash;

                // playCount is your number of days played based on your strategy / exit
                for (games = 0; games < maxGames; games++)
                {
                    Shuffle(ref Cards, decks);//create the cards
                    PlayBigDeck(ref Cards, ref cash, startingCash, ref results, csvWriter);

                    if (cash <= 0)
                        break;
                    if (quitWhenAhead)
                    {
                        if (cash >= startingCash * percentGains)
                            break;
                    }
                }
                csvWriter.WriteLine("{0}, {1}, {2}", cash, 0, lifeTimeCash);
                csvWriter.Flush();

                lifeTimeCash += cash;
                totalCash += cash;
                lifeTimeNumPlays++;

                DisplayResults(cash, games, results);
            }
            DisplayResults(totalCash, totalGames, results);
            csvWriter.Close();
        }
Пример #9
0
        private void HitStayBust(ref Card[] Cards, ref int index,
            ref CardHand myHand, ref CardHand dealerHand, int maxPlayers,
            int mySeat, bool doubled)
        {
            int stayAt = System.Convert.ToInt32(txtStayAt.Text, 10);
            bool dealerTen = System.Convert.ToBoolean(chkDealerTen.Checked);
            bool agg456 = System.Convert.ToBoolean(chk456.Checked);

            for (int dealto = 0; dealto < maxPlayers + 1; dealto++)
            {
                if (dealto == mySeat)
                {
                    if (dealerTen && dealerHand.Showing == 10)
                    {
                        stayAt = 16;
                    }
                    else if (agg456 && (dealerHand.Showing == 4 ||
                        dealerHand.Showing == 5 ||
                        dealerHand.Showing == 6))
                    {
                        stayAt = 12;
                    }
                    else
                    {
                        stayAt = stayAt;//normal
                    }

                    //take some cards (or not)
                    while (myHand.Total < stayAt)
                    {
                        myHand.AddCard(Cards[index]);
                        Cards[index].Dealt = true;
                        CountCard(Cards[index].Value);
                        index++;
                        if (doubled)
                            break;//double-down only gets one card
                    }
                }
                else if (dealto == maxPlayers)//the Dealer
                {
                    while (dealerHand.Total < 17)
                    {
                        dealerHand.AddCard(Cards[index]);
                        Cards[index].Dealt = true;
                        CountCard(Cards[index].Value);
                        index++;
                    }
                }
                else
                {
                    Random rand = new Random();
                    int burn = rand.Next(0, 3);
                    for (int b = 0; b < burn; b++)
                    {
                        Cards[index].Dealt = true;
                        CountCard(Cards[index].Value);
                        index++;
                    }
                }

            }
        }
Пример #10
0
        private void InitialDeal(ref Card[] Cards, ref int index,
            ref CardHand myHand, ref CardHand dealerHand,
            int mySeat, int maxPlayers)
        {
            for (int i = 0; i < 2; i++)//two cards each
            {
                for (int dealto = 0; dealto < maxPlayers + 1; dealto++)
                {
                    //count cards
                    CountCard(Cards[index].Value);

                    //Deal
                    if (dealto == mySeat)
                    {
                        myHand.Cards[i].Value = Cards[index].Value;
                        myHand.Cards[i].Suit = Cards[index].Suit;
                    }
                    else if (dealto == maxPlayers)//the Dealer
                    {
                        dealerHand.Cards[i].Value = Cards[index].Value;
                        dealerHand.Cards[i].Suit = Cards[index].Suit;
                    }
                    //else {deal this card to some random person}
                    Cards[index].Dealt = true;
                    index++;
                }
            }
        }
Пример #11
0
		public CardHand( int numCards )
		{
			Cards = new Card[numCards];
			for ( int i=0; i<numCards; i++ )
				Cards[i] = new Card();
		}