private void SendResultToPlayers() { playerManager.ForEach((player) => { BlackjackPlayer bPlayer = player as BlackjackPlayer; if (bPlayer.status == PlayerStatus.Playing) { BlackjackDeckResults deckResults = new BlackjackDeckResults(); deckResults.deckResults = new List <BlackjackResult>(); int moneyDelta = 0; for (int i = 0; i < playerCards[bPlayer].Count; i++) { BlackjackResult result = GetGameResult(bPlayer, i, playerBetsDic[player].initialBet); deckResults.deckResults.Add(result); moneyDelta += result.Money; } GameResultResponse response = new GameResultResponse(); response.deckResults = PacketHelper.Serialize <BlackjackDeckResults>(deckResults); response.BetMoney = playerBetsDic[player].initialBet; response.DealerCards = PacketHelper.Serialize <CardSet>(dealerCards); bPlayer.peer.SendOperationResponse(new OperationResponse(CommonOperationCode.BaccaratGameResult, response), new SendParameters()); bPlayer.money += moneyDelta; //WebHelper.UpdatePlayerMoney(player.name, moneyDelta); } else { GameResultResponse response = new GameResultResponse(); response.BetMoney = 0; response.DealerCards = PacketHelper.Serialize <CardSet>(dealerCards); bPlayer.peer.SendOperationResponse(new OperationResponse(CommonOperationCode.BaccaratGameResult, response), new SendParameters()); } }); }
public void ComputeStandEV(List <Card> playersHand, List <Card> dealersCards, Double previousProb) { foreach (Card c in simpleCardList) { List <Card> dealersCards_clone = new List <Card>(dealersCards); // Clone playersHand so can be passed "ByVal" dealersCards_clone.Add(c); if (BlackJack.getHandValue(dealersCards_clone) > 16) // TODO: only S17 { BlackjackResult bjr = BlackJack.getGameResult(dealersCards_clone, playersHand); // A push or a win is a win if (bjr == BlackjackResult.PlayerWins) { masterWinProbSum = masterWinProbSum + (previousProb * getInfiniteDeckProb(c, dealersCards)); } else if (bjr == BlackjackResult.Push) { masterPushProbSum = masterPushProbSum + (previousProb * getInfiniteDeckProb(c, dealersCards)); } else { masterLoseProbSum = masterLoseProbSum + (previousProb * getInfiniteDeckProb(c, dealersCards)); } } else { Double curentProb = getInfiniteDeckProb(c, dealersCards); ComputeStandEV(playersHand, dealersCards_clone, previousProb * curentProb); } } }
// Used by PlayTimedGame to process the players winnings public static void processPlayerWinnings(BSPlayer player, BSDealer dealer) { // If this player is playing (do they have cards?) // cant use "hasQuit", because that's set in the previous loop, and the player may still need to be processed if (player.getHand(0).Count > 0) { // Loop through each hand the player has (Split Hands) for (int j = 0; j < player.getHandCount(); j++) { BlackjackResult bjr = BlackJack.getGameResult(dealer.getHand(), player.getHand(j)); // Give player the money / take it away if (bjr == BlackjackResult.PlayerWins) { // If the player wins, has only one hand and has blackjack then pay 3:2 instead of 1:1 if ((player.getHandCount() == 1) & (BlackJack.doesHandHaveBlackjack(player.getHand(j)))) { player.winBlackJack(j); } else { player.winNormalBet(j); } } else if (bjr == BlackjackResult.Push) { player.pushBet(j); } else // Dealer Wins { player.loseBet(j); } } } }
private void dealerDraw(List <int> skipList, List <Card> card_list, List <Card> dealersCards, List <Card> playersCards, Player_Statistics ps) { for (int i = 0; i < card_list.Count; i++) { if (!(isSkipIndex(i, skipList))) { // Make Clones so the lists can be passed "ByValue" List <int> skipList_clone = new List <int>(skipList); List <Card> dealersCards_clone = new List <Card>(dealersCards); dealersCards_clone.Add(card_list.ElementAt(i)); if (BlackJack.getHandValue(dealersCards_clone) < 17) { skipList_clone.Add(i); dealerDraw(skipList_clone, card_list, dealersCards_clone, playersCards, ps); } else { // Dealer will stand on S17 BlackjackResult bjr = BlackJack.getGameResult(dealersCards_clone, playersCards); ps.addStat(playersCards, dealersCards_clone.ElementAt(0), bjr); // TODO: Check this if 0 is dealers first card } } } }
public void RecursiveComputer_Stay(List <Card> playersHand, List <Card> dealersCards, Double previousProb, int deckCount) { foreach (Card c in simpleCardList) { // Check to see if the current card is still in the deck. If not, then skip it. if (!(hasCardRunOut(playersHand, dealersCards, c, deckCount))) { List <Card> dealersCards_clone = new List <Card>(dealersCards); // Clone playersHand so can be passed "ByVal" dealersCards_clone.Add(c); if (BlackJack.getHandValue(dealersCards_clone) > 16) // TODO: only S17 { BlackjackResult bjr = BlackJack.getGameResult(dealersCards_clone, playersHand); // A push or a win is a win if (bjr == BlackjackResult.PlayerWins) { masterWinProbSum = masterWinProbSum + (previousProb * getProb(playersHand, dealersCards, c, deckCount)); } else if (bjr == BlackjackResult.Push) { masterPushProbSum = masterPushProbSum + (previousProb * getProb(playersHand, dealersCards, c, deckCount)); } } else { Double curentProb = getProb(playersHand, dealersCards, c, deckCount); RecursiveComputer_Stay(playersHand, dealersCards_clone, previousProb * curentProb, deckCount); } } } }
// Adds a new stat. Stats are based on the first two cards in the hand. public void addStat(List <Card> cards, Card dealersCard, BlackjackResult result) { this.totalGames += 1; int index_Dealer = getIndexFromDealerCard(dealersCard); int index_Player = getIndexFromPlayersFirstTwoCards(cards); this.CardStatsList[index_Dealer][index_Player].addStat(result); }
public BlackjackResponse( BlackjackTable table, BlackjackResult result, string message = "") { Table = table; Result = result; Message = message; }
public void ComputeEV_List_Recursive(List <Card> playersHand, List <Card> dealersCards, Double previousProb) { foreach (Card c in simpleCardList) { // Check to see if the current card is still in the deck. If not, then skip it. // if (!(hasCardRunOut(playersHand, dealersCards, c, deckCount))) // { // Check if the players hand has the right number of cards if (playersHand.Count < currentHitCount + 2) { List <Card> playersHand_clone = new List <Card>(playersHand); // Clone playersHand so can be passed "ByVal" playersHand_clone.Add(c); Double currentProb = getInfiniteDeckProb(c); if (BlackJack.getHandValue(playersHand_clone) <= 21) { ComputeEV_List_Recursive(playersHand_clone, dealersCards, previousProb * currentProb); } else { // Since the hand is over 21, don't bother checking the dealer combinations as they will always win, even when they bust. masterLoseProbSum += currentProb * previousProb; } } else // Player hand has all cards, so move onto dealer { List <Card> dealersCards_clone = new List <Card>(dealersCards); // Clone playersHand so can be passed "ByVal" dealersCards_clone.Add(c); if (BlackJack.getHandValue(dealersCards_clone) > 16) // TODO: only S17 { BlackjackResult bjr = BlackJack.getGameResult(dealersCards_clone, playersHand); // A push or a win is a win if (bjr == BlackjackResult.PlayerWins) { masterWinProbSum = masterWinProbSum + (previousProb * getInfiniteDeckProb(c, dealersCards)); winCount += 1; } else if (bjr == BlackjackResult.Push) { masterPushProbSum = masterPushProbSum + (previousProb * getInfiniteDeckProb(c, dealersCards)); pushCount += 1; } else { masterLoseProbSum = masterLoseProbSum + (previousProb * getInfiniteDeckProb(c, dealersCards)); bustCount += 1; } } else { Double curentProb = getInfiniteDeckProb(c, dealersCards); ComputeEV_List_Recursive(playersHand, dealersCards_clone, previousProb * curentProb); } } //} } }
public void getResults(List <Player> players, Player_Statistics ps) { foreach (Player p in players) { // We will test hard hands and soft hand separatly and split hands seperatly if (!p.hasAceInInitalHand() & !p.hasDoublesInInitialHand() & !this.hasBlackJack()) { BlackjackResult result = BlackJack.getGameResult(this.Cards, p.getHand(0)); ps.addStat(p.getHand(0), this.Cards[0], result); } } }
public void addStat(Card player1, Card player2, Card dealersCard, BlackjackResult result) { List <Card> cards = new List <Card>(); cards.Add(player1); cards.Add(player2); this.totalGames += 1; int index_Dealer = getIndexFromDealerCard(dealersCard); int index_Player = getIndexFromPlayersFirstTwoCards(cards); this.CardStatsList[index_Dealer][index_Player].addStat(result); }
public void ComputeHitEV_Double(List <Card> playersHand, List <Card> dealersCards, Double previousProb) { foreach (Card c in simpleCardList) { // If the player hasn't drawn a card... if (playersHand.Count < 3) { List <Card> playersHand_Clone = new List <Card>(playersHand); playersHand_Clone.Add(c); ComputeHitEV_Double(playersHand_Clone, dealersCards, getInfiniteDeckProb(c)); } else { // Special case where we havent drawn a card, but the player has 3 cards, when they have 21 if ((playersHand[0].value == CardValue.Nine) & (playersHand[1].value == CardValue.Ten) & (playersHand[2].value == CardValue.Two) & (playersHand.Count == 3)) { List <Card> playersHand_Clone = new List <Card>(playersHand); playersHand_Clone.Add(c); ComputeHitEV_Double(playersHand_Clone, dealersCards, getInfiniteDeckProb(c)); } // See how the probabilities turn out for all dealer cards else { List <Card> dealersCards_clone = new List <Card>(dealersCards); // Clone playersHand so can be passed "ByVal" dealersCards_clone.Add(c); if (BlackJack.getHandValue(dealersCards_clone) > 16) // TODO: only S17 { BlackjackResult bjr = BlackJack.getGameResult(dealersCards_clone, playersHand); // A push or a win is a win if (bjr == BlackjackResult.PlayerWins) { masterWinProbSum = masterWinProbSum + (previousProb * getInfiniteDeckProb(c, dealersCards)); } else if (bjr == BlackjackResult.Push) { masterPushProbSum = masterPushProbSum + (previousProb * getInfiniteDeckProb(c, dealersCards)); } else { masterLoseProbSum = masterLoseProbSum + (previousProb * getInfiniteDeckProb(c, dealersCards)); } } else { Double curentProb = getInfiniteDeckProb(c, dealersCards); ComputeHitEV_Double(playersHand, dealersCards_clone, previousProb * curentProb); } } } } }
public void addStat(BlackjackResult result) { if (result == BlackjackResult.PlayerWins) { wins += 1; total += 1; } else if (result == BlackjackResult.Push) { // wins += 1; //total += 1; } else if (result == BlackjackResult.DealerWins) { total += 1; } }
private BlackjackResult GetGameResult(BlackjackPlayer player, int deckIndex, int betMoney) { BlackjackResult result = new BlackjackResult(); var money = 0; //TODO: use blackjack result if (IsDoubleDowned(player, deckIndex)) { betMoney *= 2; } if (IsDealerBlackjack() && IsPlayerBlackjack(player, deckIndex)) { money = 0; result.Type = BlackjackResultType.Push; } else if (IsDealerBlackjack()) { money = -betMoney; result.Type = BlackjackResultType.Lose; } else if (IsPlayerBlackjack(player, deckIndex)) { money = betMoney * 3 / 2; result.Type = BlackjackResultType.Blackjack; } else if (IsPlayerBusted(player, deckIndex)) { money = -betMoney; result.Type = BlackjackResultType.Lose; } else if (IsDealerBusted()) { money = betMoney; result.Type = BlackjackResultType.Win; } else { int dealerBestScore = GetDealerBestScore(); int playerBestScore = GetPlayerBestScore(player, deckIndex); if (dealerBestScore < playerBestScore) { money = betMoney; result.Type = BlackjackResultType.Win; } else if (dealerBestScore > playerBestScore) { money = -betMoney; result.Type = BlackjackResultType.Lose; } else { money = 0; result.Type = BlackjackResultType.Push; } } result.Money = money; result.BetMoney = betMoney; return(result); }