/* If the user selects a card, returns the card, otherwise null */ private Card AskUserToConfirm(Bitmap targetImage, Hashtable possibleMatches) { /* * if (possibleMatches.Count == 0) * { * Globals.Director.WriteDebug(WRITE_DEBUG,"Warning: We should ask the user to confirm an image, but there are no possible matches..."); * return null; * }*/ CardMatchSelectDialog dialog = new CardMatchSelectDialog(); dialog.Location = cardMatchDialogSpawnLocation; dialog.DisplayImageToMatch(targetImage); // Create list List <String> orderedFilenames = new List <String>(); foreach (String cardMatchFile in possibleMatches.Keys) { orderedFilenames.Add(cardMatchFile); Globals.Director.WriteDebug(WRITE_DEBUG, cardMatchFile + " has similarity of " + possibleMatches[cardMatchFile]); } orderedFilenames.Sort((delegate(String file1, String file2) { return(((double)possibleMatches[file2]).CompareTo((double)possibleMatches[file1])); })); // Create cards from filenames const int MAX_CARDS_TO_DISPLAY = 5; int i = 0; foreach (String filename in orderedFilenames) { dialog.AddPossibleCardMatch(Card.CreateFromPath(filename)); i++; if (i == MAX_CARDS_TO_DISPLAY) { break; } } if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // The user selected a card Card userCard = dialog.SelectedCard; /* Before returning to the caller, we replace the image associated with the card * with the targetimage. This process allows us to slowly replace the common card images templates * with images that come directly from the poker client, allowing us to achieve an almost perfect match * the next time the same card is compared */ ReplaceTemplateImageWith(userCard, targetImage); return(userCard); } return(null); }
/* If the user selects a card, returns the card, otherwise null */ private Card AskUserToConfirm(Bitmap targetImage, Hashtable possibleMatches) { /* if (possibleMatches.Count == 0) { Trace.WriteLine("Warning: We should ask the user to confirm an image, but there are no possible matches..."); return null; }*/ CardMatchSelectDialog dialog = new CardMatchSelectDialog(); dialog.Location = cardMatchDialogSpawnLocation; dialog.DisplayImageToMatch(targetImage); // Create list List<String> orderedFilenames = new List<String>(); foreach (String cardMatchFile in possibleMatches.Keys) { orderedFilenames.Add(cardMatchFile); Trace.WriteLine(cardMatchFile + " has similarity of " + possibleMatches[cardMatchFile]); } orderedFilenames.Sort((delegate(String file1, String file2) { return ((double)possibleMatches[file2]).CompareTo((double)possibleMatches[file1]); })); // Create cards from filenames const int MAX_CARDS_TO_DISPLAY = 7; int i = 0; foreach (String filename in orderedFilenames) { dialog.AddPossibleCardMatch(Card.CreateFromPath(filename)); i++; if (i == MAX_CARDS_TO_DISPLAY) break; } if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // The user selected a card Card userCard = dialog.SelectedCard; /* Before returning to the caller, we replace the image associated with the card * with the targetimage. This process allows us to slowly replace the common card images templates * with images that come directly from the poker client, allowing us to achieve an almost perfect match * the next time the same card is compared */ ReplaceTemplateImageWith(userCard, targetImage); return userCard; } return null; }