public Deck(Deck otherDeck) { foreach (Card card in otherDeck.deck) { this.deck.Add(new Card(card)); } }
private void btnAuto_Click(object sender, EventArgs e) { myHand1.Clear(); deck = new Deck(); deck.Shuffle(); for (int i = 0; i < 7; i++) { myHand1.Add(deck.Deal()); } int x = 0; for (int i = 0; i < myHand1.Count(); i++) { Bitmap bitmap = new Bitmap(myHand1.getCard(i).getImage()); Graphics g = Graphics.FromImage(b2); g.DrawImage(bitmap, 5 + x * 75, 5, 71, 96); x++; } pictureBox1.Image = b2; }
public Table() { players = new PlayerList(); deck = new Deck(); rand = new Random(); mainPot = new Pot(); sidePots = new List<Pot>(); smallBlind = new Blind(); bigBlind = new Blind(); roundCounter = 0; turnCount = 0; dealerPosition = rand.Next(players.Count); //set blind amount and position smallBlind.Amount = 500; bigBlind.Amount = 1000; mainPot.SmallBlind = 500; mainPot.BigBlind = 1000; smallBlind.position = dealerPosition + 1; bigBlind.position = dealerPosition + 2; currentIndex = dealerPosition; }
//determine the hole cards of the player and the community cards to be dealt //determines who will win the showdown at the end public void CalculateHandValueHard(Hand otherHand,Deck deck) { Hand knownCommunityCards = new Hand(); Hand remainingCommunityCards = new Hand(); //add known community cards for (int i = 2; i < myHand.Count(); i++) { knownCommunityCards.Add(myHand[i]); } //generate remaining community cards if (knownCommunityCards.Count() < 5) { remainingCommunityCards.Add(deck.Deal()); if (knownCommunityCards.Count() < 4) { remainingCommunityCards.Add(deck.Deal()); if (knownCommunityCards.Count() < 3) { remainingCommunityCards.Add(deck.Deal()); remainingCommunityCards.Add(deck.Deal()); remainingCommunityCards.Add(deck.Deal()); } } } //add the remaining cards this.AddToHand(remainingCommunityCards); otherHand += remainingCommunityCards; otherHand += knownCommunityCards; //compare hands if (HandCombination.getBestHandEfficiently(new Hand(myHand)) > HandCombination.getBestHandEfficiently(new Hand(otherHand))) handValue = 1; else if (HandCombination.getBestHandEfficiently(new Hand(myHand)) < HandCombination.getBestHandEfficiently(new Hand(otherHand))) handValue = 0; else handValue = 0.5; for (int i = 0; i < remainingCommunityCards.Count(); i++) { myHand.Remove(remainingCommunityCards[i]); } }
//using the monte carlo method, calculate a hand value for the AI's current hand //this can be very hard on the computer's memory and processor and can result in lag time public void CalculateHandValue(int count) { double score = 0; PlayerList playerList = new PlayerList(); for (int i = 0; i < count - 1; i++) { playerList.Add(new Player()); } Hand bestHand = new Hand(); int bestHandCount = 1; Deck deck = new Deck(); Hand knownCommunityCards = new Hand(); Hand remainingCommunityCards = new Hand(); Hand myHoleCards = new Hand(); //remove known cards from deck for (int i = 0; i < myHand.Count(); i++) { deck.Remove(myHand[i]); } //add known community cards for (int i = 2; i < myHand.Count(); i++) { knownCommunityCards.Add(myHand[i]); } myHoleCards.Add(this.getHand()[0]); myHoleCards.Add(this.getHand()[1]); //loop 100 times for (int i = 0; i < 100; i++) { //reset players and shuffle deck for (int j = 0; j < playerList.Count; j++) { playerList[j].isbusted = false; playerList[j].getHand().Clear(); } myHand.Clear(); remainingCommunityCards.Clear(); deck.Shuffle(); //generate remaining community cards if (knownCommunityCards.Count() < 5) { remainingCommunityCards.Add(deck.Deal()); if (knownCommunityCards.Count() < 4) { remainingCommunityCards.Add(deck.Deal()); if (knownCommunityCards.Count() < 3) { remainingCommunityCards.Add(deck.Deal()); remainingCommunityCards.Add(deck.Deal()); remainingCommunityCards.Add(deck.Deal()); } } } //add hole/community cards to the AI this.AddToHand(knownCommunityCards); this.AddToHand(remainingCommunityCards); this.AddToHand(myHoleCards); //add hole/community cards to other players for (int j = 0; j < playerList.Count; j++) { playerList[j].AddToHand(knownCommunityCards); if (remainingCommunityCards.Count() != 0) playerList[j].AddToHand(remainingCommunityCards); playerList[j].AddToHand(deck.Deal()); playerList[j].AddToHand(deck.Deal()); //if player is dealt hole cards of less than 5-5, and no pocket pairs the player drops out if (playerList[j].getHand()[playerList[j].getHand().Count() - 1].getRank() + playerList[j].getHand()[playerList[j].getHand().Count() - 2].getRank() <= 10 && playerList[j].getHand()[playerList[j].getHand().Count() - 1].getRank() != playerList[j].getHand()[playerList[j].getHand().Count() - 2].getRank()) { playerList[j].isbusted = true; } } //add cards back to deck for (int j = 0; j < remainingCommunityCards.Count(); j++) { deck.Add(remainingCommunityCards[j]); } for (int j = 0; j < playerList.Count; j++) { deck.Add(playerList[j].getHand()[playerList[j].getHand().Count() - 1]); deck.Add(playerList[j].getHand()[playerList[j].getHand().Count() - 2]); } //compare hands bestHandCount = 1; playerList.Add(this); bestHand = playerList[0].getHand(); for (int j = 0; j <playerList.Count-1; j++) { if (playerList[j].isbusted) continue; if (HandCombination.getBestHandEfficiently(new Hand(playerList[j+1].getHand())) > HandCombination.getBestHandEfficiently(new Hand(playerList[j].getHand()))) { bestHandCount = 1; bestHand = playerList[j+1].getHand(); } else if (HandCombination.getBestHandEfficiently(new Hand(playerList[j+1].getHand())) == HandCombination.getBestHandEfficiently(new Hand(playerList[j].getHand()))) bestHandCount++; } playerList.Remove(this); //if my hand is the best, increment score if (myHand.isEqual(bestHand)) score = score + (1 / bestHandCount); } //reconstruct original hand myHand.Clear(); this.AddToHand(myHoleCards); this.AddToHand(knownCommunityCards); //calculate hand value as a percentage of wins handValue = score / 100; }
/// <summary> /// Start a new round, dealer/smallblind position are moved up one spot /// players/counter variables are reset /// blinds are reset if necessary. /// </summary> public void startNextMatch() { players.ResetPlayers(); deck = new Deck(); if (roundCounter == 10) { roundCounter = 0; smallBlind.Amount *= 2; bigBlind.Amount = smallBlind.Amount * 2; mainPot.SmallBlind = SmallBlind; mainPot.BigBlind = BigBlind; } if (roundCounter != 0) { dealerPosition = incrementIndex(dealerPosition); smallBlind.position = incrementIndex(dealerPosition); bigBlind.position = incrementIndex(smallBlind.position); } roundCounter++; mainPot.Amount = 0; mainPot.AgressorIndex = -1; mainPot.MinimumRaise = bigBlind.Amount; tableHand.Clear(); currentIndex = dealerPosition; winnermessage = null; mainPot.getPlayersInPot().Clear(); sidePots.Clear(); }