//constructor public Deck() { for (int suitVal = 0; suitVal < 4; suitVal++) { for (int rankVal = 1; rankVal < 14; rankVal++) { int val = suitVal * 13 + rankVal - 1; cards[val] = new Card((Card.Suit)suitVal, (Card.Rank)rankVal); cards[val].deckValue = val; } } }
public bool TestStraight(int n, int rnd) { // create temp hand Card[] tempHand = new Card[7]; Card[] tempHand2 = new Card[7]; Card swapCard = new Card(); int count = 0; int straightScore = 0; byte aceCount = 0; bool straight = false; // populate hand for (int c = 0; c < 7; c++) { if (c < 2) tempHand[c] = AIplayer[n].playerHand[c]; else tempHand[c] = Dealer.dealerHand[c-2]; } // check for aces for (int a = 0; a < rnd+3; a++) { if (tempHand[a].rank == Card.Rank.ace) aceCount++; } //sort hand for (int x = 0; x < rnd + 4; x++) { for (int y = x + 1; y < rnd + 3; y++) { if (tempHand[x].cardValue > tempHand[y].cardValue) { swapCard = tempHand[y]; tempHand[y] = tempHand[x]; tempHand[x] = swapCard; } } } // test for straight for (int x = 0; x < rnd + 2; x++) { if (tempHand[x].cardValue == tempHand[x+1].cardValue + 1) { count++; } } if (count >= 4) straight = true; // test for high ace if (aceCount >1 && aceCount < 4) { if (straight == true) { if ((tempHand[6].rank == Card.Rank.ace && tempHand[5].rank == Card.Rank.king) || (tempHand[5].rank == Card.Rank.ace && tempHand[4].rank == Card.Rank.king) || (tempHand[4].rank == Card.Rank.ace && tempHand[3].rank == Card.Rank.king)) { AIplayer[n].aceHigh = true; } } // test for low ace if (!AIplayer[n].aceHigh) { tempHand2 = tempHand; // reassign card value for (int z = 0; z < rnd+4; z++) { if (tempHand2[z].cardValue == 14) { tempHand2[z].cardValue = 1; } } // re-sort for (int x = 0; x < rnd + 4; x++) { for (int y = x + 1; y < rnd + 3; y++) { if (tempHand2[x].cardValue > tempHand2[y].cardValue) { swapCard = tempHand2[y]; tempHand2[y] = tempHand2[x]; tempHand2[x] = swapCard; } } } // re-check for straight int count2 = 0; for (int x = 0; x < rnd + 2; x++) { if (tempHand[x].cardValue == tempHand[x+1].cardValue + 1) { count2++; } } if (count2 >= 4) { straight = true; AIplayer[n].aceLow = true; } } if (straight) { return straight; } else return false; } return false; }
public void scoreHandAI(int n, int rnd) { int myScore = 0; int cardsScore = 0; int kindScore = 0; int royalCount = 0; bool winTestTemp; bool isStraight = false; bool isFlush = false; int HighCardScore = 0; int adjustScore = 0; int cards = 0; // bet round 1 testing if (rnd < 2) { if (AIplayer[n].playerHand[0].rank == AIplayer[n].playerHand[1].rank) AIplayer[n].winHands = Player.winHand.pair; if (AIplayer[n].winHands != Player.winHand.pair) { // test for possible flush if (AIplayer[n].playerHand[0].suit == AIplayer[n].playerHand[1].suit) { AIplayer[n].winHands = Player.winHand.flush; isFlush = true; //AIplayer[n].winHands = Player.winHand.flush; } // test for possible straight if (AIplayer[n].playerHand[1].cardValue == AIplayer[n].playerHand[0].cardValue + 1 || AIplayer[n].playerHand[0].cardValue == AIplayer[n].playerHand[1].cardValue + 1 || (AIplayer[n].playerHand[0].rank == Card.Rank.ace && AIplayer[n].playerHand[1].rank == Card.Rank.deuce) || (AIplayer[n].playerHand[1].rank == Card.Rank.ace && AIplayer[n].playerHand[0].rank == Card.Rank.deuce)) { isStraight = true; // test for possible straight flush if (isStraight) { if (isFlush) { AIplayer[n].winHands = Player.winHand.straightflush; // test for possible royal flush if (AIplayer[n].winHands == Player.winHand.straightflush) { for (int k = 0; k < 2; k++) { if (AIplayer[n].playerHand[k].rank == Card.Rank.ace || AIplayer[n].playerHand[k].rank == Card.Rank.king || AIplayer[n].playerHand[k].rank == Card.Rank.queen || AIplayer[n].playerHand[k].rank == Card.Rank.jack || AIplayer[n].playerHand[k].rank == Card.Rank.ten) { royalCount++; continue; } } if (royalCount > 1) AIplayer[n].winHands = Player.winHand.royalflush; } } else AIplayer[n].winHands = Player.winHand.straight; } } } } else // if rnd > 1 { // create temp hand switch (rnd) { case 2: cards = 5; break; case 3: cards = 6; break; case 4: cards = 7; break; } Card[] tempHand = new Card[cards]; for (int c = 0; c < cards; c++) { if (c < 2) tempHand[c] = AIplayer[n].playerHand[c]; else tempHand[c] = Dealer.dealerHand[c - 2]; } isFlush = TestFlush(n, rnd); if (isFlush) AIplayer[n].winHands = Player.winHand.flush; isStraight = TestStraight(n, rnd); if (isStraight) { if (isStraight && isFlush) { if (AIplayer[n].aceHigh) AIplayer[n].winHands = Player.winHand.royalflush; else AIplayer[n].winHands = Player.winHand.straightflush; } else AIplayer[n].winHands = Player.winHand.straight; } if (isStraight == false && isFlush == false) { kindScore = TestPairKind(AIplayer[n], rnd); switch (kindScore) { case 1: AIplayer[n].winHands = Player.winHand.pair; break; case 2: AIplayer[n].winHands = Player.winHand.twopair; break; case 3: AIplayer[n].winHands = Player.winHand.threekind; break; case 4: AIplayer[n].winHands = Player.winHand.fullhouse; break; case 6: AIplayer[n].winHands = Player.winHand.fourkind; break; } } } // give scores and test high cards if (AIplayer[n].winHands != Player.winHand.none) { // score royal flush if (AIplayer[n].winHands == Player.winHand.royalflush) { if (rnd < 2) AIplayer[n].handScore = 150; else AIplayer[n].handScore = 2000; } // score straight flush if (AIplayer[n].winHands == Player.winHand.straightflush) { if (rnd < 2) AIplayer[n].handScore = 150; else { AIplayer[n].handScore = 1500; } } // score four of a kind if (AIplayer[n].winHands == Player.winHand.fourkind) { AIplayer[n].handScore = 1200; } // score full house if (AIplayer[n].winHands == Player.winHand.fullhouse) { AIplayer[n].handScore = 1000; } // score flush if (AIplayer[n].winHands == Player.winHand.flush) { if (rnd < 2) AIplayer[n].handScore = 100; else { AIplayer[n].handScore = 300; } } // score straight if (AIplayer[n].winHands == Player.winHand.straight) { if (rnd < 2) AIplayer[n].handScore = 120; else { AIplayer[n].handScore = 200; } } // score three of a kind if (AIplayer[n].winHands == Player.winHand.threekind) { AIplayer[n].handScore = 100; } // score two pair if (AIplayer[n].winHands == Player.winHand.twopair) { AIplayer[n].handScore = 100; } // score pair if (AIplayer[n].winHands == Player.winHand.pair) { if (rnd < 2) AIplayer[n].handScore = 700; else AIplayer[n].handScore = 100; } } AddRankValues(n, rnd); }
public bool TestFlush(int n, int rnd) { // create temp hand Card[] tempHand = new Card[7]; int count = 0; // populate hand for (int c = 0; c < 7; c++) { if (c < 2) tempHand[c] = AIplayer[n].playerHand[c]; else tempHand[c] = Dealer.dealerHand[c-2]; } //test for flush for (int x = 0; x < rnd + 4; x++) { for (int y = x + 1; y < rnd + 3; y++) { if (tempHand[x].suit == tempHand[y].suit) { count++; if (count >= 4) { return true; } } } } return false; }
public int TestPairKind(Player playerTemp, int rnd) { int s = 0; // create temp hand Card[] tempHand = new Card[7]; for (int c = 0; c < 7; c++) { if (c < 2) tempHand[c] = playerTemp.playerHand[c]; else tempHand[c] = Dealer.dealerHand[c-2]; } for (int x = 0; x < rnd + 4; x++) { for (int y = x + 1; y < rnd + 3; y++) { if (tempHand[x].rank == tempHand[y].rank) { s++; } } } return s; }
public void DetermineHandWinner() { if (mainPlayer.betStatus == Player.betstats.fold) mainPlayer.winHandScore = 0; else ScorePlayerHand(); int adjustScore = 0; // create some tempory players Player[] tempPlayers = new Player[5]; for (int i = 0; i < 4; i++) { if (AIplayer[i].isBust) { AIplayer[i].winHandScore = 0; } tempPlayers[i] = AIplayer[i].ShallowCopy(); } tempPlayers[4] = mainPlayer.ShallowCopy(); // score winning hands for (int k = 0; k < 5; k++) { if (tempPlayers[k].isBust) continue; // set up temp hand Card[] tempHand = new Card[7]; Card swapCard = new Card(); for (int y = 0; y < 7; y++) { if (y < 2) tempHand[y] = tempPlayers[k].playerHand[y].ShallowCopy(); else tempHand[y] = Dealer.dealerHand[y - 2].ShallowCopy(); } for (int j = 0; j < 7; j++) { tempPlayers[k].playerTempHand[j] = tempHand[j].ShallowCopy(); } //sort tempHand for (int a = 0; a < 6; a++) { for (int b = a + 1; b < 7; b++) { if (tempHand[a].cardValue > tempHand[b].cardValue) { swapCard = tempHand[b]; tempHand[b] = tempHand[a]; tempHand[a] = swapCard; } } } if (tempPlayers[k].betStatus == Player.betstats.fold) { tempPlayers[k].winHandScore = 0; continue; } switch (tempPlayers[k].winHands) { case Player.winHand.none: tempPlayers[k].winHandScore = 0; break; case Player.winHand.pair: tempPlayers[k].winHandScore = 100; break; case Player.winHand.twopair: tempPlayers[k].winHandScore = 200; break; case Player.winHand.threekind: tempPlayers[k].winHandScore = 300; break; case Player.winHand.straight: tempPlayers[k].winHandScore = 400; break; case Player.winHand.flush: tempPlayers[k].winHandScore = 500; break; case Player.winHand.fullhouse: tempPlayers[k].winHandScore = 600; break; case Player.winHand.fourkind: tempPlayers[k].winHandScore = 700; break; case Player.winHand.straightflush: tempPlayers[k].winHandScore = 800; break; case Player.winHand.royalflush: tempPlayers[k].winHandScore = 900; break; } // adjust scores for high cards for (int a = 0; a < 7; a++) { switch (tempHand[a].rank) { case Card.Rank.ace: if (tempPlayers[k].aceLow) { adjustScore = adjustScore + 1; } else adjustScore = adjustScore + 14; break; case Card.Rank.king: adjustScore = adjustScore + 13; break; case Card.Rank.queen: adjustScore = adjustScore + 12; break; case Card.Rank.jack: adjustScore = adjustScore + 11; break; case Card.Rank.ten: adjustScore = adjustScore + 10; break; case Card.Rank.nine: adjustScore = adjustScore + 9; break; case Card.Rank.eight: adjustScore = adjustScore + 8; break; case Card.Rank.seven: adjustScore = adjustScore + 7; break; case Card.Rank.six: adjustScore = adjustScore + 6; break; case Card.Rank.five: adjustScore = adjustScore + 5; break; case Card.Rank.four: adjustScore = adjustScore + 4; break; case Card.Rank.three: adjustScore = adjustScore + 3; break; case Card.Rank.deuce: adjustScore = adjustScore + 2; break; } } tempPlayers[k].winHandScore = tempPlayers[k].winHandScore + adjustScore; } Player swapPlayerTemp = new Player(); // find hand winner for (int x = 0; x < 4; x++) { for (int y = x + 1; y < 5; y++) { if (tempPlayers[x].winHandScore > tempPlayers[y].winHandScore) { swapPlayerTemp = tempPlayers[y]; tempPlayers[y] = tempPlayers[x]; tempPlayers[x] = swapPlayerTemp; } } } // check for ties int winner = 1; int q = 4; /* for (int i = 4; i < 3; i--) { if (tempPlayers[i].winHandScore == tempPlayers[i - 1].winHandScore) winner = winner + 1; else break; } */ if (tempPlayers[4].winHandScore != 0) { //set winner(s) if (tempPlayers[4].name == mainPlayer.name) { mainPlayer.isHandWinner = true; } else { for (int z = 0; z < 4; z++) { if (tempPlayers[4].name == AIplayer[z].name) AIplayer[z].isHandWinner = true; } } if (winner > 1) { for (int n = 3; n < 2; n--) { if (tempPlayers[n].name == mainPlayer.name) mainPlayer.isHandWinner = true; else { for (int m = 0; m < 4; m++) { if (tempPlayers[n].name == AIplayer[m].name) AIplayer[m].isHandWinner = true; } } } } tempPlayers[4].winnings = pot / winner; if (mainPlayer.isHandWinner) { mainPlayer.winnings = tempPlayers[4].winnings; mainPlayer.money = mainPlayer.money + mainPlayer.winnings; } else { for (int t = 0; t < 4; t++) { if (AIplayer[t].isHandWinner) { AIplayer[t].winnings = tempPlayers[4].winnings; AIplayer[t].money = AIplayer[t].money + AIplayer[t].winnings; } if (AIplayer[t].money <= 0) AIplayer[t].isBust = true; } } } // use for testing purposes /* if (!qualified) { makePlayerGoBust(); } */ pot = 0; winnerHand = tempPlayers[4].ShallowCopy(); if (mainPlayer.money <= 0) { mainPlayer.isBust = true; EndGame(); return; } winResults form2 = new winResults(this); form2.Show(); return; }
// begin hand public void StartHand() { //declare objects and variables Deck cardDeck = new Deck(); // generate a new deck of cards pot = 0; // reset pot to $0 Dealer.flopDeal = 0; // AI players ante up and reset values for (int x = 0; x < 4; x++) { pot = pot + ante; AIplayer[x].money = AIplayer[x].money - ante; /* AIplayer[x].aceHigh = false; AIplayer[x].bet = 0; AIplayer[x].betStatus = Player.betstats.none; AIplayer[x].handScore = 0; AIplayer[x].isRaising = false; AIplayer[x].raiseCount = 0; AIplayer[x].winHands = Player.winHand.none; AIplayer[x].winHandScore = 0; */ } pot = pot + ante; //ante for main player mainPlayer.money = mainPlayer.money - ante; UpdateUI(); // pick cards for main player for (int d = 0; d < 2; d++) { int n = 0; while (n == 0) { int cardPick = random1.Next(0, 51); if (!cardDeck.cards[cardPick].isPicked) { Card cardTemp = new Card(); cardTemp = cardDeck.cards[cardPick]; mainPlayer.playerHand[d] = cardTemp; cardDeck.cards[cardPick].isPicked = true; n++; } else { continue; } } } // pick cards for AI players for (int i = 0; i < 4; i++) { if (!AIplayer[i].isBust) { for (int j = 0; j < 2; j++) { int n = 0; while (n == 0) { int cardPick = random1.Next(0, 51); if (!cardDeck.cards[cardPick].isPicked) { Card cardTemp = new Card(); cardTemp = cardDeck.cards[cardPick]; AIplayer[i].playerHand[j] = cardTemp; cardDeck.cards[cardPick].isPicked = true; n++; } else { continue; } } } } continue; } // pick cards for dealer for (int d = 0; d < 5; d++) { int n = 0; while (n == 0) { int cardPick = random1.Next(0, 51); if (!cardDeck.cards[cardPick].isPicked) { Card cardTemp = new Card(); cardTemp = cardDeck.cards[cardPick]; Dealer.dealerHand[d] = cardTemp; cardDeck.cards[cardPick].isPicked = true; n++; } else { continue; } } } currentBet = 0; //int playerNum = 0; betRound = 1; firstBet = true; PlayHand(); }
public bool TestStraight(int n, int rnd) { // create temp hand Card swapCard = new Card(); int count = 0; int cards = 0; byte aceCount = 0; bool straight = false; switch (rnd) { case 2: cards = 5; break; case 3: cards = 6; break; case 4: cards = 7; break; } Card[] tempHand = new Card[cards]; Card[] tempHand2 = new Card[cards]; // populate temporary hand #1 for (int c = 0; c < cards; c++) { if (c < 2) { tempHand[c] = AIplayer[n].playerHand[c].ShallowCopy(); tempHand2[c] = AIplayer[n].playerHand[c].ShallowCopy(); } else { tempHand[c] = Dealer.dealerHand[c - 2].ShallowCopy(); tempHand2[c] = Dealer.dealerHand[c - 2].ShallowCopy(); } } // check for aces for (int a = 0; a < cards; a++) { if (tempHand[a].rank == Card.Rank.ace) aceCount++; } //sort hand for (int x = 0; x < cards-1; x++) { for (int y = x + 1; y < cards; y++) { if (tempHand[x].cardValue > tempHand[y].cardValue) { swapCard = tempHand[y]; tempHand[y] = tempHand[x]; tempHand[x] = swapCard; } } } // test for straight for (int x = 0; x < cards - 1; x++) { if (tempHand[x + 1].cardValue == tempHand[x].cardValue + 1) { count++; } else count = 0; } if (count >= 4) straight = true; // test for high ace if (aceCount >0 && aceCount < 4) { if (straight == true) { if ((tempHand[cards-1].rank == Card.Rank.ace && tempHand[cards-2].rank == Card.Rank.king) || (tempHand[cards - 2].rank == Card.Rank.ace && tempHand[cards - 3].rank == Card.Rank.king) || (tempHand[cards - 3].rank == Card.Rank.ace && tempHand[cards - 4].rank == Card.Rank.king)) { AIplayer[n].aceHigh = true; } } // test for low ace if (!AIplayer[n].aceHigh) { // reassign card value for (int z = 0; z < cards; z++) { if (tempHand2[z].cardValue == 14) { tempHand2[z].cardValue = 1; } } // re-sort for (int x = 0; x < cards-1; x++) { for (int y = x + 1; y < cards; y++) { if (tempHand2[x].cardValue > tempHand2[y].cardValue) { swapCard = tempHand2[y]; tempHand2[y] = tempHand2[x]; tempHand2[x] = swapCard; } } } // re-check for straight int count2 = 0; for (int x = 0; x < rnd + 2; x++) { if (tempHand[x].cardValue == tempHand[x+1].cardValue + 1) { count2++; } } if (count2 >= 4) { straight = true; AIplayer[n].aceLow = true; } } if (straight) { return straight; } else return false; } return false; }
public int TestPairKind(int n, int rnd) { int s = 0; int s2 = 0; int cards = 0; // create temp hand switch (rnd) { case 2: cards = 5; break; case 3: cards = 6; break; case 4: cards = 7; break; } Card[] tempHand = new Card[cards]; Card[] tempHand2 = new Card[cards]; for (int c = 0; c < cards; c++) { if (c < 2) tempHand[c] = AIplayer[n].playerHand[c].ShallowCopy(); else tempHand[c] = Dealer.dealerHand[c-2].ShallowCopy(); } for (int x = 0; x < cards-1; x++) { if (tempHand[x].isPaired) continue; for (int y = x + 1; y < cards; y++) { if (tempHand[x].cardValue == tempHand[y].cardValue) { s++; tempHand2[s - 1] = tempHand[y].ShallowCopy(); tempHand[y].isPaired = true; } } } if (s > 1) { for (int a = 0; a < s - 1; a++) { for (int b = a + 1; b < s; b++) { if (tempHand2[a].cardValue == tempHand2[b].cardValue) s2++; } } if ((s == 2 && s2 == 0) || (s == 3 && s2 == 0)) return 2; if (s == 2 && s2 == 1) return 3; if ((s == 3 && s2 == 1) || (s == 4 && s2 == 1) || (s == 4 && s2 == 2)) return 4; if ((s == 3 && s2 == 3) || (s == 4 && s2 == 3) || (s == 3 && s2 == 2) || (s == 5 && s2 == 3)) return 6; } else return s; return s; }
public bool TestFlush(int n, int rnd) { // create temp hand int heartCount = 0; int spadeCount = 0; int clubCount = 0; int diamondCount = 0; int cards = 0; switch (rnd) { case 2: cards = 5; break; case 3: cards = 6; break; case 4: cards = 7; break; } Card[] tempHand = new Card[cards]; // populate hand for (int c = 0; c < cards; c++) { Card tempCard = new Card(); tempHand[c] = tempCard; if (c < 2) tempHand[c] = AIplayer[n].playerHand[c]; else tempHand[c] = Dealer.dealerHand[c-2]; } //test for flush for (int x = 0; x < cards; x++) { if (tempHand[x].suit == Card.Suit.club) { clubCount++; if (clubCount >= 5) { return true; } } if (tempHand[x].suit == Card.Suit.diamond) { diamondCount++; if (diamondCount >= 5) { return true; } } if (tempHand[x].suit == Card.Suit.heart) { heartCount++; if (heartCount >= 5) { return true; } } if (tempHand[x].suit == Card.Suit.spade) { spadeCount++; if (spadeCount >= 5) { return true; } } } return false; }
// begin hand public void StartHand() { //declare objects and variables Deck cardDeck = new Deck(); // generate a new deck of cards pot = 0; // reset pot to $0 Dealer.flopDeal = 0; // AI players ante up and reset values for (int x = 0; x < 4; x++) { if (!AIplayer[x].isBust) { pot = pot + ante; AIplayer[x].money = AIplayer[x].money - ante; if (AIplayer[x].money < 0) { AIplayer[x].money = 0; AIplayer[x].isBust = true; } } } pot = pot + ante; //ante for main player mainPlayer.money = mainPlayer.money - ante; if (mainPlayer.money < 0) { mainPlayer.money = 0; EndGame(); return; } UpdateUI(); // pick cards for main player for (int d = 0; d < 2; d++) { int n = 0; while (n == 0) { int cardPick = random1.Next(0, 51); if (!cardDeck.cards[cardPick].isPicked) { Card cardTemp = new Card(); cardTemp = cardDeck.cards[cardPick]; mainPlayer.playerHand[d] = cardTemp; cardDeck.cards[cardPick].isPicked = true; n++; } else { continue; } } } // pick cards for AI players for (int i = 0; i < 4; i++) { if (!AIplayer[i].isBust) { for (int j = 0; j < 2; j++) { int n = 0; while (n == 0) { int cardPick = random1.Next(0, 51); if (!cardDeck.cards[cardPick].isPicked) { Card cardTemp = new Card(); cardTemp = cardDeck.cards[cardPick]; AIplayer[i].playerHand[j] = cardTemp; cardDeck.cards[cardPick].isPicked = true; n++; } else { continue; } } } } continue; } // pick cards for dealer for (int d = 0; d < 5; d++) { int n = 0; while (n == 0) { int cardPick = random1.Next(0, 51); if (!cardDeck.cards[cardPick].isPicked) { Card cardTemp = new Card(); cardTemp = cardDeck.cards[cardPick]; Dealer.dealerHand[d] = cardTemp; cardDeck.cards[cardPick].isPicked = true; n++; } else { continue; } } } currentBet = 0; betRound = 1; firstBet = true; callCount = 0; AIfoldCount = 0; finishedAIBetRound = false; finishedHand = false; nextBetRound = false; isChecked = false; isRaised = false; ResetAllPlayers(); PlayHand(); }
public void ScorePlayerHand() { bool isFlush = false; bool isStraight = false; int count = 0; int heartCount = 0; int spadeCount = 0; int clubCount = 0; int diamondCount = 0; //int straightScore = 0; byte aceCount = 0; Card[] tempHand = new Card[7]; Card[] tempHand2 = new Card[7]; Card[] tempHand3 = new Card[7]; Card swapCard = new Card(); for (int c = 0; c < 7; c++) { tempHand[c] = new Card(); ; tempHand2[c] = new Card(); ; tempHand3[c] = new Card(); ; if (c < 2) { tempHand[c] = mainPlayer.playerHand[c].ShallowCopy(); tempHand2[c] = mainPlayer.playerHand[c].ShallowCopy(); tempHand3[c] = mainPlayer.playerHand[c].ShallowCopy(); } else { tempHand[c] = Dealer.dealerHand[c - 2].ShallowCopy(); tempHand2[c] = Dealer.dealerHand[c - 2].ShallowCopy(); tempHand3[c] = Dealer.dealerHand[c - 2].ShallowCopy(); } } for (int x = 0; x < 7; x++) { if (tempHand[x].suit == Card.Suit.club) { clubCount++; if (clubCount >= 5) { mainPlayer.winHands = Player.winHand.flush; break; } } if (tempHand[x].suit == Card.Suit.diamond) { diamondCount++; if (diamondCount >= 5) { mainPlayer.winHands = Player.winHand.flush; break; } } if (tempHand[x].suit == Card.Suit.heart) { heartCount++; if (heartCount >= 5) { mainPlayer.winHands = Player.winHand.flush; break; } } if (tempHand[x].suit == Card.Suit.spade) spadeCount++; { if (spadeCount >= 5) { mainPlayer.winHands = Player.winHand.flush; break; } } } // check for aces for (int a = 0; a < 7; a++) { if (tempHand[a].rank == Card.Rank.ace) aceCount++; } //sort hand for (int x = 0; x < 6; x++) { for (int y = x + 1; y < 7; y++) { if (tempHand[x].cardValue > tempHand[y].cardValue) { swapCard = tempHand[y]; tempHand[y] = tempHand[x]; tempHand[x] = swapCard; } } } // test for straight for (int x = 0; x < 6; x++) { if (tempHand[x].cardValue == tempHand[x+1].cardValue + 1) { count++; } } if (count >= 4) isStraight = true; // test for high ace if (aceCount >1 && aceCount < 4) { if (isStraight == true) { if ((tempHand[6].rank == Card.Rank.ace && tempHand[5].rank == Card.Rank.king) || (tempHand[5].rank == Card.Rank.ace && tempHand[4].rank == Card.Rank.king) || (tempHand[4].rank == Card.Rank.ace && tempHand[3].rank == Card.Rank.king)) { mainPlayer.aceHigh = true; } } // test for low ace if (!mainPlayer.aceHigh) { tempHand2 = tempHand; // reassign card value for (int z = 0; z < 7; z++) { if (tempHand2[z].cardValue == 14) { tempHand2[z].cardValue = 1; //mainPlayer.playerHand[0].cardValue; } } // re-sort for (int x = 0; x < 6; x++) { for (int y = x + 1; y < 7; y++) { if (tempHand2[x].cardValue > tempHand2[y].cardValue) { swapCard = tempHand2[y]; tempHand2[y] = tempHand2[x]; tempHand2[x] = swapCard; } } } // re-check for straight int count2 = 0; for (int x = 0; x < 6; x++) { if (tempHand[x].cardValue == tempHand[x+1].cardValue + 1) { count2++; } } if (count2 >= 4) { isStraight = true; mainPlayer.aceLow = true; } } } if (isStraight) { if (isFlush) { if (mainPlayer.aceHigh) { mainPlayer.winHands = Player.winHand.royalflush; } else mainPlayer.winHands = Player.winHand.straightflush; } else mainPlayer.winHands = Player.winHand.straight; } // test for pairs or a-kind if (mainPlayer.winHands == Player.winHand.none) { int s = 0; int s2 = 0; for (int x = 0; x < 6; x++) { if (tempHand[x].isPaired) continue; for (int y = x + 1; y < 7; y++) { if (tempHand[x].cardValue == tempHand[y].cardValue) { s++; tempHand3[s - 1] = tempHand[y]; tempHand[y].isPaired = true; } } } if (s > 1) { for (int a = 0; a < s - 1; a++) { for (int b = a + 1; b < s; b++) { if (tempHand3[a].cardValue == tempHand3[b].cardValue) s2++; } } if ((s == 2 && s2 == 0) || (s == 3 && s2 == 0)) s = 2; if (s == 2 && s2 == 1) s = 3; if ((s == 3 && s2 == 1) || (s == 4 && s2 == 1) || (s == 4 && s2 == 2)) s = 4; if ((s == 3 && s2 == 3) || (s == 4 && s2 == 3)) s = 6; } if (s > 0) { switch (s) { case 1: mainPlayer.winHands = Player.winHand.pair; break; case 2: mainPlayer.winHands = Player.winHand.twopair; break; case 3: mainPlayer.winHands = Player.winHand.threekind; break; case 4: mainPlayer.winHands = Player.winHand.fullhouse; break; case 6: mainPlayer.winHands = Player.winHand.fourkind; break; } } else mainPlayer.winHands = Player.winHand.none; } }