public bool CheckStraight( ref PlayCard[] cards ) { int wasted = 0; for (int i = 0; i < cards.Length - 4; ++i) { if (wasted > 2) return false; int start = (int)cards[i].Value; int end = start == 5 ? 13 : start - 4; int[] pos = new int[5] { i, -1, -1, -1, -1 }; for (int j = i + 1; j < cards.Length; ++j) { if ((int)cards[j].Value != start - 1) { if (++wasted > 2) return false; if ((int)cards[i + 1].Value != start) break; } else { for (int k = 1; k < 5; ++k) { if (pos[k] == -1) { pos[k] = j; break; } } if (pos[4] != -1) break; else if (start == 2) start = 13; else --start; } } if (pos[4] != -1) { cards = new PlayCard[5] { cards[pos[0]], cards[pos[1]], cards[pos[2]], cards[pos[3]], cards[pos[4]] }; return true; } } return false; }
public bool CheckFlush( ref PlayCard[] cards ) { int spades = 0; int hearts = 0; int diamonds = 0; int clubs = 0; for (int i = 0; i < cards.Length; ++i) { if (cards[i].Colour == CardColour.Spade) ++spades; else if (cards[i].Colour == CardColour.Heart) ++hearts; else if (cards[i].Colour == CardColour.Diamond) ++diamonds; else ++clubs; } if (spades == 7 || hearts == 7 || diamonds == 7 || clubs == 7) return true; else if (spades < 5 && hearts < 5 && diamonds < 5 && clubs < 5) return false; if ( spades >= 5 ) cards = RemoveCardsNotOfColor( CardColour.Spade, cards ); else if (hearts >= 5) cards = RemoveCardsNotOfColor( CardColour.Heart, cards ); else if (diamonds >= 5) cards = RemoveCardsNotOfColor( CardColour.Diamond, cards ); else cards = RemoveCardsNotOfColor( CardColour.Club, cards ); return true; }
public PlayCard[] RemoveCardsNotOfColor( CardColour colour, PlayCard[] cards ) { int[] pos = new int[6] { -1, -1, -1, -1, -1, -1 }; for (int i = 0; i < cards.Length; ++i) { if (cards[i].Colour == colour) { for (int j = 0; j < 6; ++j) { if (pos[j] == -1) { pos[j] = i; break; } } } } if (pos[5] != -1) { return new PlayCard[6] { cards[pos[0]], cards[pos[1]], cards[pos[2]], cards[pos[3]], cards[pos[4]], cards[pos[5]], }; } else { return new PlayCard[5] { cards[pos[0]], cards[pos[1]], cards[pos[2]], cards[pos[3]], cards[pos[4]], }; } }
public void OnFour( ref PlayCard[] cards, int start ) { if (start == 0) { cards = new PlayCard[5] { cards[0], cards[1], cards[2], cards[3], cards[4] }; } else { cards = new PlayCard[5] { cards[start], cards[start + 1], cards[start + 2], cards[start + 3], cards[0] }; } }
public PlayCard[] SortCardsByValue( PlayCard[] flop, PlayCard turn, PlayCard river, PlayCard[] hand ) { PlayCard[] cards = new PlayCard[7] { flop[0], flop[1], flop[2], turn, river, hand[0], hand[1] }; for (int i = 0; i < 6; ++i) { for (int j = 1; j + i < 7; ++j) { if (cards[i].Value < cards[i + j].Value) { PlayCard temp = cards[i]; cards[i] = cards[i + j]; cards[i + j] = temp; } } } return cards; }
public void OnFullHouse( ref PlayCard[] cards, int startthree, int starttwo ) { cards = new PlayCard[5] { cards[startthree], cards[startthree + 1], cards[startthree + 2], cards[starttwo], cards[starttwo + 1] }; }
public HandType CheckMultiCards( ref PlayCard[] cards ) { //int same = 1; int twostart1 = -1; int twostart2 = -1; int twostart3 = -1; int threestart1 = -1; int threestart2 = -1; int start = 0; int current = 0; for (int i = 0; i < cards.Length - 1; ++i) { if (cards[i].Value == cards[i + 1].Value && i != cards.Length - 2) { if (++current == 4) { OnFour( ref cards, start ); return HandType.Four; } } else { if (cards[i].Value == cards[i + 1].Value && ++current == 4) { OnFour( ref cards, start ); return HandType.Four; } else if (current == 3) { if (threestart1 == -1) { threestart1 = start; } else { threestart2 = start; break; } } else if (current == 2) { if (twostart1 == -1) { twostart1 = start; } else if (twostart2 == -1) { twostart2 = start; if (threestart1 != -1) break; } else { twostart3 = start; break; } } start = i; //same = 1; } } if (threestart1 != -1) { if (threestart2 != -1) { if (cards[threestart1].Value > cards[threestart2].Value) OnFullHouse( ref cards, threestart1, threestart2 ); else OnFullHouse( ref cards, threestart2, threestart1 ); return HandType.FullHouse; } else if (twostart1 != -1) { if (twostart2 != -1 && cards[twostart2].Value > cards[twostart1].Value) OnFullHouse( ref cards, threestart1, threestart2 ); else OnFullHouse( ref cards, threestart1, twostart1 ); return HandType.FullHouse; } else { if (threestart1 == 0) { cards = new PlayCard[5] { cards[0], cards[1], cards[2], cards[3], cards[4] }; } else if (threestart1 == 1) { cards = new PlayCard[5] { cards[1], cards[2], cards[3], cards[0], cards[4] }; } else { cards = new PlayCard[5] { cards[threestart1], cards[threestart1 + 1], cards[threestart1 + 2], cards[0], cards[1] }; } return HandType.Three; } } else if (twostart1 != -1) { if (twostart2 != -1) { if (twostart3 != -1 && !(cards[twostart1].Value > cards[twostart3].Value && cards[twostart2].Value > cards[twostart3].Value)) { } else { int high = 0; if (twostart1 == 0 || twostart2 == 0) { if (twostart1 == 2 || twostart2 == 2) high = 4; else high = 2; } if (cards[twostart1].Value > cards[twostart2].Value) { cards = new PlayCard[5] { cards[twostart1], cards[twostart1 + 1], cards[twostart2], cards[twostart2 + 1], cards[high] }; } else { cards = new PlayCard[5] { cards[twostart2], cards[twostart2 + 1], cards[twostart1], cards[twostart1 + 1], cards[high] }; } } return HandType.TwoPairs; } else if (twostart1 == 0) { cards = new PlayCard[5] { cards[0], cards[1], cards[2], cards[3], cards[4] }; } else if (twostart1 == 1) { cards = new PlayCard[5] { cards[1], cards[2], cards[0], cards[3], cards[4] }; } else if (twostart1 == 2) { cards = new PlayCard[5] { cards[2], cards[3], cards[0], cards[1], cards[4] }; } else { cards = new PlayCard[5] { cards[twostart1], cards[twostart1 + 1], cards[0], cards[1], cards[2] }; } return HandType.Pair; } else return HandType.HighCard; }
public void DoRiver() { int i = Utility.Random( m_Set.Count ); m_River = m_Set[i]; m_Drawn.Add( m_Set[i] ); m_Set.RemoveAt( i ); }
public void DoTurn() { int i = Utility.Random( m_Set.Count ); m_Turn = m_Set[i]; m_Drawn.Add( m_Set[i] ); m_Set.RemoveAt(i); }
public void StartNextRound() { int count = 0; for (int i = 0; i < m_Players.Count; ++i) { if (m_Players[i].Chips > 0) { m_Players[i].DidFold = false; if (m_Players[i].BetToPot != 0) Console.WriteLine( "Possible PokerBug with spliting pot." ); m_Players[i].BetToPot = 0; m_Players[i].LastHand = m_Players[i].Hand; m_Players[i].Hand[0] = null; m_Players[i].Hand[1] = null; m_Players[i].LastAction = ""; ++count; } else m_Players[i].IsOut = true; } if (count == 1) { PayWager( m_Players[0].Player ); ResetToDefaults(); } else { m_Flop = null; m_Turn = null; m_River = null; for (int i = m_Drawn.Count - 1; i >= 0; --i) m_Set.Add( m_Drawn[i] ); m_Drawn.Clear(); m_DealerButton = GetNextPlayer( m_DealerButton ); PayBlinds(); GiveCards(); ShowGumps(); } }