public static Card[] RetrieveCommunityCards() { Bitmap currentCommunityCards = CaptureCommunityCardsImage(); int foundCount = 0; int cardsToSearch; Card[] hand; //Check to see how many cards you need to find, if no cards are on the table return null. if (BitmapHandler.SearchBitmap(currentCommunityCards, RetrieveBitmap("3cards"))) { cardsToSearch = 3; hand = new Card[3]; } else if (BitmapHandler.SearchBitmap(currentCommunityCards, RetrieveBitmap("4cards"))) { cardsToSearch = 4; hand = new Card[4]; } else if (BitmapHandler.SearchBitmap(currentCommunityCards, RetrieveBitmap("5cards"))) { cardsToSearch = 5; hand = new Card[5]; } else { return null; } foreach (NamedBitmap cardImage in cardPics) { if (BitmapHandler.SearchBitmap(currentCommunityCards, cardImage.bitmap)) { //Split the Bitmap filenames up into two seperate strings. EX) filename == S7, then stringSuit = "S", and stringRank = "7" string stringSuit = cardImage.name.Substring(0, 1); string stringRank = cardImage.name.Substring(1); //Get the Bitmap filenames into Suit and Rank Enums. EX) filename == S7, then cardSuit = Suit.Spades, and cardRank = Rank.Seven Card.Suit cardSuit = ConvertStringToSuit(stringSuit); Card.Rank cardRank = ConvertStringToRank(stringRank); hand[foundCount] = new Card(cardSuit, cardRank); foundCount++; //If you found all the cards, stop searching if (foundCount == cardsToSearch) { break; } } } return hand; }
public static Card[] RetrieveYourHand() { Bitmap currentHand = CaptureYourHandImage(); //First check to see if there are no cards in your hand to avoid unnessicary searching. if (BitmapHandler.SearchBitmap(currentHand, RetrieveBitmap("NoHand"))) { return null; } else { int foundCount = 0; int cardsToSearch = 2; Card[] hand = new Card[2]; foreach (NamedBitmap cardImage in cardPics) { if (BitmapHandler.SearchBitmap(currentHand, cardImage.bitmap)) { //Split the Bitmap filenames up into two seperate strings. EX) filename == S7, then stringSuit = "S", and stringRank = "7" string stringSuit = cardImage.name.Substring(0, 1); string stringRank = cardImage.name.Substring(1); //Get the Bitmap filenames into Suit and Rank Enums. EX) filename == S7, then cardSuit = Suit.Spades, and cardRank = Rank.Seven Card.Suit cardSuit = ConvertStringToSuit(stringSuit); Card.Rank cardRank = ConvertStringToRank(stringRank); hand[foundCount] = new Card(cardSuit, cardRank); foundCount++; //If you found all the cards, stop searching if (foundCount == cardsToSearch) { break; } } } return hand; } }