/// <summary> /// Decides winner between 2 parties /// </summary> /// <param name="hand"></param> /// <param name="hand"></param> private Hand WinDecider(Hand hand1, Hand hand2) { //conditions to win //only decides on who wins, doesn't transfer the money if (hand2.fold == false && hand1.fold == false) //if both hands haven't folded { if (hand2.Score() > hand1.Score()) //hand 2 wins { hand1.winner = false; hand2.winner = true; return(hand2); } else if (hand1.Score() > hand2.Score()) //hand 1 wins //(if both hands haven't folded) Hand1 must be higher than hand2, not have folded or be higher than 21 || hand2 has folded but hand1 hasn't { hand1.winner = true; hand2.winner = false; return(hand1); } else //if theres a tie and both players haven't folded { Random rnd = new Random(); //new randomizer int coin = rnd.Next(0, 2); if (coin == 1) //flip of a coin decides winner (Heads) { hand1.winner = true; hand2.winner = false; return(hand1); //hand1 wins } else //Tails { hand1.winner = false; hand2.winner = true; return(hand2); //hand2 wins } } } else if (hand2.fold == false || hand1.fold == true) //hand 2 fold, hand 1 hasn't { hand1.winner = false; hand2.winner = true; return(hand2); } else if (hand1.fold == false || hand2.fold == true) //hand 2 folded, but hand 1 hasn't { hand1.winner = true; hand2.winner = false; return(hand1); } else //if no player is qualified to win { MessageBox.Show("both failed"); return(hand1); //either hand can be played. both have lost } }
/// <summary> /// determines likelyhood of bot making a decision. (Chooses a strategy) /// </summary> /// <param name="fChance"></param> /// <param name="rChance"></param> /// <param name="hmChance"></param> private void BOTStrat(int fChance, int rChance, int hmChance, Hand BOT) { //on a scale of 1 - 6, how likely? if (BOT.Score() < 6 && BOT.Score() >= 0) //if i have x amount of cards, my likely hood of y would be: { rChance = 1; hmChance = 6; fChance = 3; } else if (BOT.Score() < 11 && BOT.Score() >= 6) //very { rChance = 2; hmChance = 5; fChance = 2; } else if (BOT.Score() < 16 && BOT.Score() >= 11) //not very { rChance = 3; hmChance = 2; fChance = 0; } else if (BOT.Score() < 21 && BOT.Score() >= 16) //high unlikely { rChance = 5; hmChance = 1; fChance = 0; } if (BOT.match < 20) //if less than $20 has been made as a bet { rChance = 5; } }
private void HitMe(object sender, EventArgs e) //Hit me { if (hit == false && player.Score() <= 21) //if the player hasn't folded or picked up this round { player.stand = false; StandButton.Text = "Next"; HitMe(player, HitMeButton); hit = true; HitMeButton.Text = "Wait Next turn"; } if (player.Score() > 21) //if the player breaks the card limit { player.fold = true; HitMeButton.Visible = false; RaiseButton1.Visible = false; } }
/// <summary> /// decides winner between 3 players /// </summary> /// <param name="hand1"></param> /// <param name="hand2"></param> /// <param name="hand3"></param> private void WinDecider(Hand hand1, Hand hand2, Hand hand3) { MessageBox.Show(hand1.name + "vs" + hand2.name); Hand tempWinner = WinDecider(hand1, hand2); //first 2 hands compared. best contender chosen MessageBox.Show(tempWinner.name + " " + tempWinner.Score()); MessageBox.Show(hand3.name + "vs" + tempWinner.name); Hand realWin = WinDecider(tempWinner, hand3); //final hand is checked to see if It has the best conditions to win MessageBox.Show(realWin.name + realWin.Score()); SearchWinner(hand1, hand2, hand3); //searches for who the decided winner is }