// Decide based on basic strategy private void Decide(int Player_Value, int Dealer_Value) { Console.WriteLine("Deciding.."); // Stand on player value 17+ if (Player_Value > 16 && Player_Value < 22) { Stand_Button.PerformClick(); } // Stand on player 13-16 and dealer up card < 7 else if ((Player_Value > 12 && Player_Value < 17) && (Dealer_Value < 7)) { Stand_Button.PerformClick(); } // Hit on player 13-16 when dealer shows 7+ else if ((Player_Value > 12 && Player_Value < 17) && (Dealer_Value > 6)) { Hit_Button.PerformClick(); } // Hit on player 12 when dealer shows 2-3 else if ((Player_Value == 12) && ((Dealer_Value == 2 && Dealer_Value == 3) || Dealer_Value > 6)) { Hit_Button.PerformClick(); } // stand on player 12 and dealer shows 4-6 else if ((Player_Value == 12) && (Dealer_Value > 3 && Dealer_Value < 7)) { Hit_Button.PerformClick(); } // Hit on player 11 and dealer Ace else if ((Player_Value == 11) && (Dealer_Value == 1)) { Hit_Button.PerformClick(); } // Hit on player 10 and dealer 10 or Ace else if ((Player_Value == 10) && (Dealer_Value == 1 || Dealer_Value == 10)) { Hit_Button.PerformClick(); } // Hit on player 9 and dealer 2 or 7+ else if ((Player_Value == 9) && (Dealer_Value == 2 || Dealer_Value == 1 || Dealer_Value > 6)) { Hit_Button.PerformClick(); } // Hit on player 5-8 else if (Player_Value > 4 && Player_Value < 9) { Hit_Button.PerformClick(); } // Player_Decision_TextBox.Text = Player_Current_Total.ToString(); }
// decide based on basic strategy, (aces present) private void Decide(string Player_Value, string Dealer_Value) { //Console.WriteLine("Deciding with aces.."); // DEALER ACE CASE and player no ace if (Dealer_Value.Contains('/') && !Player_Value.Contains('/')) { int Value = Convert.ToInt32(Player_Value); // stand on 17+ and dealer Ace if (Value > 17) { Stand_Button.PerformClick(); } // if player has <17, hit else { Hit_Button.PerformClick(); } } // PLAYER ACE CASE and Dealer does not else if (!Dealer_Value.Contains('/') && Player_Value.Contains('/')) { int Value = Convert.ToInt32(Dealer_Value); // always stand on soft 19+ if (Player_Value.Contains("9/19") || Player_Value.Contains("10/20")) { Stand_Button.PerformClick(); } // stand on soft 18 when dealer shoes 8- else if (Player_Value.Contains("8/18") && Value < 9) { Stand_Button.PerformClick(); } // hit on soft 18 when dealer shoes 9+ else if (Player_Value.Contains("8/18") && Value > 9) { Stand_Button.PerformClick(); } // hit rest of soft hands (3/13 - 7/17) (double downs have been taken care of before this function call) else if (Player_Value.Contains("2/12") || (Player_Value.Contains("3/13")) || (Player_Value.Contains("4/14")) || (Player_Value.Contains("5/15")) || (Player_Value.Contains("6/16")) || (Player_Value.Contains("7/17"))) { Hit_Button.PerformClick(); } } //Player_Decision_TextBox.Text = Player_Current_Total.ToString(); }
// Player doubles bet and draws 1 more card private void Double_Button_Click(object sender, EventArgs e) { Doubled_Previous_Hand = true; Current_Bet *= 2; //Console.WriteLine("Double Button Click: " + Current_Bet); Bet_TextBox.Text = string.Format("{0:0.00}", Current_Bet); if (!d.Is_Empty()) { Card c = d.Draw(); Player_Card_3.Image = c.Get_Image(); // Check for ace if (Player_Result_TextBox.Text.Contains('/')) { // check for 21 if (Player_Current_Total + 11 == 21) { Player_Current_Total = 21; Player_Result_TextBox.Text = "21"; Stand_Button.PerformClick(); } //no 21 - perform calculation with ace in hand else { int Possible_Value_1 = Player_Current_Total + c.Get_Integer_Value(); int Possible_Value_2 = Possible_Value_1 + 10; Player_Current_Total = Possible_Value_1; Player_Result_TextBox.Text = Possible_Value_1.ToString() + "/" + Possible_Value_2.ToString(); Player_Hand_Count++; // end hand if player busts and reveal dealer card if (Player_Current_Total > 21) { Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); // Dealer results not calculated since player busted Decision(true, false, false, false); return; } } } else { Player_Current_Total += c.Get_Integer_Value(); Player_Result_TextBox.Text = Player_Current_Total.ToString(); Player_Hand_Count++; // end hand if player busts and reveal dealer card if (Player_Current_Total > 21) { Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); // Dealer results not calculated since player busted Decision(true, false, false, false); return; } } } // empty shoe else { Display_Empty_Message(); return; } // reduce current bet from double amount //Console.WriteLine("div"); //Current_Bet /= 2; }
// Dealing of initial 4 cards. async private void Deal_Button_Click_1(object sender, EventArgs e) { Status_Label.Text = "Status: Round in Progress."; Decision_Reached = false; int Deal_Value = 0; Console.WriteLine("New hand ================================"); while (Deal_Value < 4) { if (!d.Is_Empty()) { Card c = d.Draw(); // Draw facedown on dealer's first turn if ((Dealer_Hand_Count == 0) && (!Player_Turn)) { Dealer_Down_Card = c; // If the facedown card is a 10, flag it if (Dealer_Down_Card.Get_Integer_Value() == 10) { Face_Down_Ten = true; } Dealer_Card_1.Image = c.Get_Image_FaceDown(); Dealer_Hand_Count++; Player_Turn = true; } else if (Player_Turn) { if (Player_Hand_Count == 0) { Player_Card_1.Image = c.Get_Image(); Player_First_Card = c.Get_Integer_Value(); } else if (Player_Hand_Count == 1) { Player_Card_2.Image = c.Get_Image(); Player_Second_Card = c.Get_Integer_Value(); // pause to display card await Task.Delay(DELAY_TASK_TIME); } // Check for ACE if (c.Get_Integer_Value() == 1) { //Console.WriteLine("WTF"); Player_Ace = true; // If first card is Ace if (Player_Hand_Count == 0) { Player_Current_Total += 1; Player_Result_TextBox.Text = "1/11"; } // Condition (A, A) - total will be 0 else if (Player_Current_Total == 0) { Player_Current_Total += 1; } // (x, A) condition else { Player_Current_Total += 1; } // Create string ex. (5/15) string Possible_Sums = ""; //Player_Current_Total += c.Get_Integer_Value(); Possible_Sums += Player_Current_Total.ToString() + "/" + (Player_Current_Total + 10).ToString(); Player_Result_TextBox.Text = Possible_Sums; // if BJ with (x, A) if ((Player_Current_Total + 10) == 21) { Decision(false, false, true, false); return; } // If soft 18+ - Stand else if (Player_Current_Total + 10 >= 18) { Console.WriteLine("236"); Player_Result_TextBox.Text = (Player_Current_Total + 10).ToString(); //Stand_Button.PerformClick(); premature stand: stand before dealer dealt his 2nd // instead of standing, just end player's turn Player_Turn = false; //return;// } } // (A, X) Condition else { //Console.WriteLine("214"); if (Player_Result_TextBox.Text.Contains('/')) { string Possible_Sums = ""; Player_Current_Total += c.Get_Integer_Value(); // BJ (A, 10) condition if ((Player_Current_Total + 10) == 21) { Player_Result_TextBox.Text = Player_Current_Total.ToString(); if (d.Is_Empty()) { // draw dealer's second card before calling Decision() to end turn; Dealer_Card_2.Image = d.Draw().Get_Image(); Decision(false, false, true, false); return; } // empty shoe else { Display_Empty_Message(); return; } //Clear_Button.PerformClick(); } Possible_Sums += Player_Current_Total.ToString() + "/" + (Player_Current_Total + 10).ToString(); Player_Result_TextBox.Text = Possible_Sums; } else { Player_Current_Total += c.Get_Integer_Value(); // (this value is calculated, this needs to be calculated) Player_Result_TextBox.Text = Player_Current_Total.ToString(); } } Player_Hand_Count++; Player_Turn = false; } // Dealer's turn else { if (Dealer_Hand_Count == 1) { Dealer_Card_2.Image = c.Get_Image(); } //Console.WriteLine("287: wtf is it doing"); // (-, A) Condition if (c.Get_Integer_Value() == 1) { // check for BJ outright //if (Dealer_Down_Card.Get_Integer_Value() + 11 == 21) if (Face_Down_Ten) { Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); Decision(false, false, false, true); return; } //string Possible_Values = ""; Dealer_Current_Total += 1; // 11 Dealer_Result_TextBox.Text = "1/11"; // dealer still has a face down. Dealer_Hand_Count++; Player_Turn = true; } else { Dealer_Current_Total += c.Get_Integer_Value(); Dealer_Result_TextBox.Text = Dealer_Current_Total.ToString(); Dealer_Hand_Count++; Player_Turn = true; } } //textBox2.Text = d.Display_Discard_Pile_ToString(); //textBox1.Text = d.Display_Deck_ToString(); } else { textBox2.Text = "Empty deck."; return; } //Remaining_Cards_Count_TextBox.Text = d.Get_Remaining_Cards().ToString(); Deal_Value++; //Console.WriteLine("Deal_Value: " + Deal_Value); // delay await Task.Delay(DELAY_TASK_TIME); } //Console.WriteLine("251: Deal_Value: " + Deal_Value); New_Hand = false; // Keep buttons disabled during initial dealing if (Dealer_Hand_Count >= 2) { Hit_Button.Enabled = true; Stand_Button.Enabled = true; Deal_Button.Enabled = false; Double_Button.Enabled = true; // if (Double_Down(Player_First_Card, Player_Second_Card)) { Player_First_Card = Player_Second_Card = 0; Double_Button.PerformClick(); // Stand to end player turn after double Stand_Button.PerformClick(); //return; // not tested // reset bet from doubling //Current_Bet /= 2; } Player_First_Card = Player_Second_Card = 0; } //Console.WriteLine("Decision Reached: " + Decision_Reached.ToString()); // make decision if player_decision_Textbox is empty (no decision) // reasons that it would not be empty are in player blackjack or outright WIN/LOSS // changed from if to while to allow multiple hits by player //while (Player_Decision_TextBox.Text.Equals("") && Deal_Value > 3) // added second condition 11:23 am 10/17 while ((!Decision_Reached) && Player_Decision_TextBox.Text.Equals("")) { // why is playeR_current_Total = if Deal_Value is 4???? //Console.WriteLine("INSIDE DEAL FUNCTION"); // if no aces, pass int values if (!Player_Result_TextBox.Text.Contains('/') && (!Dealer_Result_TextBox.Text.Contains('/'))) { // if the decision is NOT empty, a winner has been decided. //Console.WriteLine("This portion should only be executed at the end of a hand."); //Console.WriteLine("Deal_Value: " + Deal_Value); Console.WriteLine("314: Player_Result_TextBox: " + Player_Result_TextBox.Text + " Dealer_Result_TextBox: " + Dealer_Result_TextBox.Text); Decide(Convert.ToInt32(Player_Result_TextBox.Text), Convert.ToInt32(Dealer_Result_TextBox.Text)); } // if there are aces, else { Decide(Player_Result_TextBox.Text, Dealer_Result_TextBox.Text); } // update Player_Decision_TextBox value to exit loop // Maybe update player deciion textbox inside Decide(); } //Decision_Reached = false; // tried to click clear here, doesn't work // delay before dealing next hand /*if (!d.Is_Empty()) * { * * await Task.Delay(DELAY_TASK_TIME); * Deal_Button.PerformClick(); * } * else * { * Display_Empty_Message(); * }*/ }
private void Hit_Button_Click(object sender, EventArgs e) { Player_Turn = true; if (!d.Is_Empty()) { Card c = d.Draw(); //update textbox Remaining_Cards_Count_TextBox.Text = d.Get_Remaining_Cards().ToString(); if (Player_Hand_Count == 2) { Player_Card_3.Image = c.Get_Image(); } else if (Player_Hand_Count == 3) { Player_Card_4.Image = c.Get_Image(); } else if (Player_Hand_Count == 4) { Player_Card_5.Image = c.Get_Image(); } else if (Player_Hand_Count == 5) { Player_Card_6.Image = c.Get_Image(); } else if (Player_Hand_Count == 6) { Player_Card_7.Image = c.Get_Image(); } // Check for ace if (Player_Result_TextBox.Text.Contains('/')) { // check for 21 if (Player_Current_Total + 11 == 21) { Player_Current_Total = 21; Player_Result_TextBox.Text = "21"; Stand_Button.PerformClick(); } //no 21 - perform calculation with ace in hand else { int Possible_Value_1 = Player_Current_Total + c.Get_Integer_Value(); int Possible_Value_2 = Possible_Value_1 + 10; Player_Current_Total = Possible_Value_1; Player_Result_TextBox.Text = Possible_Value_1.ToString() + "/" + Possible_Value_2.ToString(); Player_Hand_Count++; // end hand if player busts and reveal dealer card if (Player_Current_Total > 21) { Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); // Dealer results not calculated since player busted Decision(true, false, false, false); return; } } } else { Player_Current_Total += c.Get_Integer_Value(); Player_Result_TextBox.Text = Player_Current_Total.ToString(); Player_Hand_Count++; // end hand if player busts and reveal dealer card if (Player_Current_Total > 21) { Dealer_Card_1.Image = Dealer_Down_Card.Get_Image(); // Dealer results not calculated since player busted Decision(true, false, false, false); return; } } } // else deck is empty else { Display_Empty_Message(); return; } }