// Added to make old code compile public Deck(int size, ShuffleType shuffleType) { // Setup the cardCOunter object this.cardCounter = new CardCounting(new BlackJackGameParams()); this.DeckList = new List <Card>(); for (int x = 0; x < size; x++) { fillWith52Cards(); } this.DeckList_Backup = new List <Card>(); this.shuffleType = shuffleType; }
public Deck(int size, ShuffleType shuffleType, CardCounting cardCounter) { // Setup the cardCOunter object this.cardCounter = cardCounter; this.DeckList = new List <Card>(); for (int x = 0; x < size; x++) { fillWith52Cards(); } this.DeckList_Backup = new List <Card>(); this.shuffleType = shuffleType; }
// 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); } }
// 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"); } }
public void playHand(BSDealer dealer, CardCounting cardCounter) { // We know the dealer doesn't have blackjack because this is tested before this portion of the game even occurs Stack <Card> splitCards = new Stack <Card>(); // Make a stack for holding the split cards int processesListCount = 0; // Keeps track of how many lists have been processed (Also reports the current lists index // While there are cards in the split pile, or their are unprocessed lists... while ((splitCards.Count > 0) | (processesListCount < this.cardList.Count)) { // If we have the same number of lists as we have processed, we must have to handle another split if (this.cardList.Count == processesListCount) { // Add the split card to the new list this.cardList.Add(new List <Card>()); // Add a new wager to the new hand this.currentBet.Add(this.initialBet); this.playerWin.Add(0); // Add the card to the new hand this.cardList[processesListCount].Add(splitCards.Pop()); } // Check if the hand has at least two cards, if it does'nt, then add one. This happens when we split if (this.cardList[processesListCount].Count == 1) { this.cardList[processesListCount].Add(dealer.takeHit()); } // Check if the higher, and lower values are both busted. If so then we've busted this hand so move to the next. if ((BlackJack.getHandValue_Lower(this.cardList[processesListCount]) > 21) & (BlackJack.getHandValue_Lower(this.cardList[processesListCount]) > 21)) { processesListCount += 1; } else { // Get the Basic Strategy move for the current card list BlackJackMove bjm = new BlackJackMove(); // If the player has doubles, but not enough money to split, then find an alternative move if (hasDoublesInHand(processesListCount) & hasQuit) { bjm = bsc.GetStrategyPairToNoPair(this.cardList[processesListCount], dealer.getUpCard()); } else { bjm = bsc.GetStrategy(this.cardList[processesListCount], dealer.getUpCard()); } switch (bjm) { case BlackJackMove.Stay: processesListCount += 1; break; case BlackJackMove.Hit: this.cardList[processesListCount].Add(dealer.takeHit()); // Add a card but don't finish processing this hand break; case BlackJackMove.Double: if (this.cardList[processesListCount].Count == 2) { // If we have enough money to double then do it, otherwise leave the table after the end of the round if ((BankRoll - currentBet[processesListCount]) > 0) { this.cardList[processesListCount].Add(dealer.takeHit()); this.BankRoll -= this.currentBet[processesListCount]; this.currentBet[processesListCount] = 2 * this.currentBet[processesListCount]; processesListCount += 1; break; } else { // Take a hit if we can't double due to money, and mark this as our last round to minimize losses hasQuit = true; this.cardList[processesListCount].Add(dealer.takeHit()); break; } } else { this.cardList[processesListCount].Add(dealer.takeHit()); // Add a card but don't finish processing this hand break; } case BlackJackMove.Double_Stay: // If we haven't hit this hand yet then double, otherwise stay if (this.cardList[processesListCount].Count == 2) { // If we have enough money to double then do it, otherwise leave the table. if ((BankRoll - currentBet[processesListCount]) > 0) { this.cardList[processesListCount].Add(dealer.takeHit()); this.BankRoll -= this.currentBet[processesListCount]; this.currentBet[processesListCount] = 2 * this.currentBet[processesListCount]; processesListCount += 1; break; } else { // Stay if we can't double due to money, and mark this as our last round to minimize losses hasQuit = true; processesListCount += 1; break; } } else { processesListCount += 1; break; } case BlackJackMove.Split: // Put the card from index 0 of the current hand into the stack. // Now, don't increment the processListCount, and reprocesses this hand. // It will only have one card so we will have to add that first. if (((BankRoll - this.initialBet) > 0) & (cardList.Count < 4)) { BankRoll -= this.initialBet; splitCards.Push(this.cardList[processesListCount][1]); this.cardList[processesListCount].RemoveAt(1); break; } else { // If we can't split due to money, then re-evaluate as a hard/soft hand and determine the new best move, mark // as the last turn to minimize losses hasQuit = true; break; } } } } // Even odds paid on split card blackjack }