bool is2Pair() { int cardcounter = 0; for (int i = 0; i < fullHand.Length; i++) { for (int j = i + 1; j < fullHand.Length; j++) { //Pair check if (fullHand[i].Cn == fullHand[j].Cn) { if (HighestCard != Cards.CardNum.DEFAULT && HighestCard < fullHand[i].Cn) { HighestCard = fullHand[i].Cn; } else if (HighestCard == Cards.CardNum.DEFAULT) { HighestCard = fullHand[i].Cn; } cardcounter++; } } } if (cardcounter == 2) { return(true); } return(false); }
bool isStraight() { for (int i = (int)Cards.CardNum.ACE; i >= 0; i--) { if (i >= (int)Cards.CardNum.JACK && i <= (int)Cards.CardNum.KING) { continue; } if (CheckCardInHand((Cards.CardNum)i)) { for (int j = 1; j < 5; j++) { if (!CheckCardInHand((Cards.CardNum)((i + j) % 13))) { break; } if (j == 4) { HighestCard = (Cards.CardNum)((i + j) % 13); return(true); } } } } return(false); }
bool isThreeOKind(int index) { for (int i = index; i < 3; i++) { int cardcounter = 0; for (int j = i + 1; j < fullHand.Length; j++) { if (fullHand[i].Cn == fullHand[j].Cn) { cardcounter++; } } if (cardcounter == 2) { if (HighestCard != Cards.CardNum.DEFAULT && HighestCard < fullHand[i].Cn) { HighestCard = fullHand[i].Cn; } else if (HighestCard == Cards.CardNum.DEFAULT) { HighestCard = fullHand[i].Cn; } return(true); } } return(false); }
bool CheckCardInHand(Cards.CardNum cn) { for (int x = 0; x < fullHand.Length; x++) { if (fullHand[x].Cn == cn) { return(true); } } return(false); }
bool isPair() { for (int i = 0; i < fullHand.Length; i++) { for (int j = i + 1; j < fullHand.Length; j++) { if (fullHand[i].Cn == fullHand[j].Cn) { if (HighestCard != Cards.CardNum.DEFAULT && HighestCard < fullHand[i].Cn) { HighestCard = fullHand[i].Cn; } else if (HighestCard == Cards.CardNum.DEFAULT) { HighestCard = fullHand[i].Cn; } return(true); } } } return(false); }
bool isFourOKind() { for (int i = 0; i < 4; i++) { int cardcounter = 0; for (int j = i + 1; j < fullHand.Length; j++) { if (fullHand[i].Cn == fullHand[j].Cn) { cardcounter++; } } if (cardcounter == 3) { HighestCard = fullHand[i].Cn; return(true); } } return(false); }
bool isFlush() { HighestCard = Cards.CardNum.DEFAULT; for (int i = 0; i < fullHand.Length; i++) { int suitcounter = 0; for (int j = i + 1; j < fullHand.Length; j++) { //Pair check if (fullHand[i].suit == fullHand[j].suit) { //Setting of the highest card number if (HighestCard != Cards.CardNum.DEFAULT && HighestCard < fullHand[i].Cn) { HighestCard = fullHand[i].Cn; } else if (HighestCard == Cards.CardNum.DEFAULT) { HighestCard = fullHand[i].Cn; } suitcounter++; } } if (suitcounter >= 4) { return(true); } else { suitcounter = 0; continue; } } return(false); }
bool isFullHouse() { HighestCard = Cards.CardNum.DEFAULT; int index = 0; for (int i = 0; i < 3; i++) { int cardcounter = 0; for (int j = i + 1; j < fullHand.Length; j++) { if (fullHand[i].Cn == fullHand[j].Cn) { index = j; cardcounter++; } } if (cardcounter == 2) { if (HighestCard != Cards.CardNum.DEFAULT && HighestCard < fullHand[i].Cn) { HighestCard = fullHand[i].Cn; } else if (HighestCard == Cards.CardNum.DEFAULT) { HighestCard = fullHand[i].Cn; } if (isPair(index)) { return(true); } } } return(false); }
bool isFourOKind() { HighestCard = Cards.CardNum.DEFAULT; groupIter = 4; for (int i = 0; i < groupIter; i++) { int cardcounter = 0; for (int j = i + 1; j < fullHand.Length; j++) { if (fullHand[i].Cn == fullHand[j].Cn) { cardcounter++; } } if (cardcounter == 3) { HighestCard = fullHand[i].Cn; return(true); } } return(false); }
// Start is called before the first frame update void Start() { dhand = DHand.DDEFAULT; HighestCard = Cards.CardNum.DEFAULT; }
public void GetWinner() { if (Player1.GetComponent <Player>().dhand == Player2.GetComponent <Player>().dhand) { //Check for flush if the table cards are already a flush resulting in tie if (Player1.GetComponent <Player>().dhand == Player.DHand.FLUSH) { int counter = 0; int[] Player1Flush = Player1.GetComponent <Player>().SortBigtoSmall(); int[] Player2Flush = Player2.GetComponent <Player>().SortBigtoSmall(); for (int x = 0; x <= 5; x++) { if (Player1Flush[x] == Player2Flush[x]) { counter++; } else { if (Player1Flush[x] > Player2Flush[x]) { GameOverText.GetComponent <Text>().text = "Player 1 Wins!"; } else if (Player2Flush[x] > Player1Flush[x]) { GameOverText.GetComponent <Text>().text = "Player 2 Wins!"; } } } if (counter == 5) { GameOverText.GetComponent <Text>().text = "Its a tie!"; } } else if (Player1.GetComponent <Player>().GetHighestCard() > Player2.GetComponent <Player>().GetHighestCard()) { GameOverText.GetComponent <Text>().text = "Player 1 Wins!"; } else if (Player1.GetComponent <Player>().GetHighestCard() == Player2.GetComponent <Player>().GetHighestCard() && Player1.GetComponent <Player>().dhand == Player.DHand.TWOPAIR) { Cards.CardNum temp1 = Cards.CardNum.DEFAULT; Cards.CardNum temp2 = Cards.CardNum.DEFAULT; for (int i = 0; i < Player1.GetComponent <Player>().GetFullHand().Length; i++) { for (int j = i + 1; j < Player1.GetComponent <Player>().GetFullHand().Length; j++) { //Pair check if (Player1.GetComponent <Player>().GetFullHand()[i].Cn == Player1.GetComponent <Player>().GetFullHand()[j].Cn) { if (Player1.GetComponent <Player>().GetFullHand()[i].Cn != Player1.GetComponent <Player>().GetHighestCard()) { temp1 = Player1.GetComponent <Player>().GetFullHand()[i].Cn; } } if (Player2.GetComponent <Player>().GetFullHand()[i].Cn == Player2.GetComponent <Player>().GetFullHand()[j].Cn) { if (Player2.GetComponent <Player>().GetFullHand()[i].Cn != Player2.GetComponent <Player>().GetHighestCard()) { temp2 = Player2.GetComponent <Player>().GetFullHand()[i].Cn; } } } } if (temp1 > temp2) { GameOverText.GetComponent <Text>().text = "Player 1 Wins"; } else if (temp1 < temp2) { GameOverText.GetComponent <Text>().text = "Player 2 Wins"; } } else if (Player1.GetComponent <Player>().GetHighestCard() == Player2.GetComponent <Player>().GetHighestCard()) { Cards.CardNum temp1 = Cards.CardNum.DEFAULT; Cards.CardNum temp2 = Cards.CardNum.DEFAULT; for (int i = 0; i < Player1.GetComponent <Player>().Hand.Length; i++) { if (temp1 == Cards.CardNum.DEFAULT) { temp1 = Player1.GetComponent <Player>().Hand[i].Cn; } else if (temp1 < Player1.GetComponent <Player>().Hand[i].Cn) { temp1 = Player1.GetComponent <Player>().Hand[i].Cn; } if (temp2 == Cards.CardNum.DEFAULT) { temp2 = Player2.GetComponent <Player>().Hand[i].Cn; } else if (temp2 < Player2.GetComponent <Player>().Hand[i].Cn) { temp2 = Player2.GetComponent <Player>().Hand[i].Cn; } if (temp1 == temp2 && i == 1 && temp1 == Player1.GetComponent <Player>().Hand[i].Cn) { temp1 = Player1.GetComponent <Player>().Hand[0].Cn; temp2 = Player2.GetComponent <Player>().Hand[0].Cn; } else if (temp1 == temp2 && i == 1 && temp1 != Player1.GetComponent <Player>().Hand[i].Cn) { temp1 = Player1.GetComponent <Player>().Hand[i].Cn; temp2 = Player2.GetComponent <Player>().Hand[i].Cn; } } if (temp1 > temp2) { GameOverText.GetComponent <Text>().text = "Player 1 Wins"; } else if (temp1 < temp2) { GameOverText.GetComponent <Text>().text = "Player 2 Wins"; } else if (temp1 == temp2) { GameOverText.GetComponent <Text>().text = "Its a tie!"; } } else { GameOverText.GetComponent <Text>().text = "Player 2 Wins"; } } else if (Player1.GetComponent <Player>().dhand > Player2.GetComponent <Player>().dhand) { GameOverText.GetComponent <Text>().text = "Player 1 Wins!"; } else if (Player1.GetComponent <Player>().dhand < Player2.GetComponent <Player>().dhand) { GameOverText.GetComponent <Text>().text = "Player 2 Wins!"; } }
// Start is called before the first frame update void Start() { groupIter = 0; dhand = DHand.DDEFAULT; HighestCard = Cards.CardNum.DEFAULT; }