public ProcessRunner(Player_Statistics Hit, Player_Statistics NoHit) { PS_NoHit = new List <Player_Statistics>(); PS_NoHit.Add(NoHit); PS_Hit = new List <Player_Statistics>(); PS_Hit.Add(Hit); }
private void testStayScenario(Player_Statistics ps, Delegate prog_del) { // Get the list of cards List <Card> card_list = new List <Card>(); Deck d = new Deck(1, Deck.ShuffleType.Durstenfeld); card_list = d.DeckList; // Test all "Stay" scenarios for (int i = 0; i < card_list.Count; i++) { Card player1 = card_list.ElementAt(i); for (int j = 0; j < card_list.Count; j++) { if (!(isSkipIndex(j, i))) { Card player2 = card_list.ElementAt(j); { if (!((player1.value == CardValue.Ace) | (player2.value == CardValue.Ace)) & !(player1 == player2)) // No soft hands { for (int k = 0; k < card_list.Count; k++) { if (!(isSkipIndex(k, i, j))) { object[] obj = new object[4]; obj[0] = i.ToString(); obj[1] = j.ToString(); obj[2] = k.ToString(); obj[3] = "Stay Round"; prog_del.DynamicInvoke((Object)obj); Card dealerUp = card_list.ElementAt(k); // Make the skip list List <int> skipList = new List <int>(); skipList.Add(i); skipList.Add(j); skipList.Add(k); // Make the dealers list List <Card> dealersList = new List <Card>(); dealersList.Add(dealerUp); // Make the players list List <Card> playersList = new List <Card>(); playersList.Add(player1); playersList.Add(player2); // Loop through all possible dealer draws dealerDraw(skipList, card_list, dealersList, playersList, ps); } } } } } } } }
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 ProcessRunner Start(Delegate prog_del) { Player_Statistics stay_stats = new Player_Statistics(); testStayScenario(stay_stats, prog_del); Player_Statistics hit_stats = new Player_Statistics(); testHitScenario(hit_stats, prog_del); return(new ProcessRunner(hit_stats, stay_stats)); }
public void playHand(Dealer dealer, List <Player> players, Player_Statistics ps) { // Rules to play the hand // In this first case, we're going to stand.. // If the dealer has blackjack, then the player cannot take any hits. THe player must // have a natural blackjack to push. if (!dealer.hasBlackJack()) { // Take as a hit until the specific count it reached while ((this.cardList[0].Count - 2) < this.HitCount) { this.cardList[0].Add(dealer.takeHit()); } } // We're always going to split Doubles.. }
public Runner(Delegate progressBarCodeDelegate, Delegate updateDeviationIterationDelegate, int iterationsForDeviationAdjutment, int iterationsOfEntireDeck, int deckCount, Deck.ShuffleType shuffleType) { // Add code to loop through and create multiple Player_Statistics objects, and then // Look at the Deviations after averaging the results. this.PS_NoHit = new List <Player_Statistics>(); this.PS_Hit = new List <Player_Statistics>(); for (int x = 0; x < iterationsForDeviationAdjutment; x++) { // Update the Deviation Iteration Label object[] obj = new object[2]; obj[0] = iterationsForDeviationAdjutment - x; updateDeviationIterationDelegate.DynamicInvoke((Object)obj); // Get the required player statistics... BlackJack BJ = new BlackJack(deckCount, true, 1, 0, "C:/BlackJack/blackJack_iter" + x.ToString() + "_0Hit.txt", false, progressBarCodeDelegate, iterationsOfEntireDeck, shuffleType); Player_Statistics PS_NoHit = BJ.start(); BJ = new BlackJack(deckCount, true, 1, 1, "C:/BlackJack/blackJack_iter" + x.ToString() + "_1Hit.txt", false, progressBarCodeDelegate, iterationsOfEntireDeck, shuffleType); Player_Statistics PS_Hit = BJ.start(); this.PS_NoHit.Add(PS_NoHit); this.PS_Hit.Add(PS_Hit); } }
public Player_Statistics start() { try { DateTime startTime = DateTime.Now; Player_Statistics ps = new Player_Statistics(); for (int x = 0; x < this.iterationsOfEntireDeck; x++) { TimeSpan ts = DateTime.Now - startTime; double minsRemaining = (ts.TotalMinutes / (double)x) * (double)(this.iterationsOfEntireDeck - x); object[] obj = new object[3]; obj[0] = this.iterationsOfEntireDeck; obj[1] = x; obj[2] = minsRemaining; this.progressUpdateCodeDelegate.DynamicInvoke((Object)obj); deck.shuffle(); while (deck.DeckList.Count >= 15) { dealer.dealCards(players); for (int y = 0; y < players.Count; y++) { players[y].playHand(dealer, players, ps); } dealer.drawTo17(); //showGameInfo(); dealer.getResults(players, ps); dealer.clearTable(players); } } ps.generateReport(this.outputFile); return(ps); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); return(null); } }
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 } } } }