public static OcrImageArea GetAreaFor(Square area, string matchingText, Point buttonLocation)
 {
     return new OcrImageArea()
     {
         _area = area,
         _matchingText = matchingText,
         _button = buttonLocation
     };
 }
        public Dictionary<int, MagicCard> DetermineCards(List<Square> cardLocations, Square setPosition, Square numberPosition, int slowDownAmount = 100, int currentCardCount = 0, int maxCardCount = 75)
        {
            Ocr ocr = new Ocr();

            _windowManager.CloseTradeCancelledDialog();

            AutoItX.Sleep(100);
            var firstPosition = cardLocations[0].MidPoint;
            AutoItX.MouseClick(firstPosition);
            AutoItX.Sleep(100);

            AutoItX.Send(Constants.HomeKey);
            AutoItX.Sleep(250);

            AutoItX.MouseMove(firstPosition.X,
                              firstPosition.Y - 35);

            Square currentCard = cardLocations[0].Copy();
            int lastCardNameChecksum = 0;
            int lastCardSetChecksum = 0;
            int currentCardSetChecksum = 1;
            int currentCardNameChecksum = 1;

            int i = 0;

            while ((!lastCardNameChecksum.Equals(currentCardNameChecksum)
                || !lastCardSetChecksum.Equals(currentCardSetChecksum))
                   && currentCardCount++ <= maxCardCount)
            {
                var j = 0;
                while (AutoItX.PixelGetColor(currentCard.Copy().MoveAlongYAxis(1).TopLeft) != _pbv.CardSelectedColor &&
                       j < 50)
                {
                    AutoItX.Sleep(50);
                    if (j == 10)
                    {
                        if (i < 4)
                        {
                            return SplitCombinedImageFile(ocr, true);
                        }
                    }

                    if (++j == 50)
                    {
                        AutoItX.Send(Constants.DownArrow);
                        AutoItX.Sleep(100);
                        if (AutoItX.PixelGetColor(currentCard.TopLeft) != _pbv.CardSelectedColor)
                        {
                            return SplitCombinedImageFile(ocr, true);
                        }
                    }
                }

                lastCardNameChecksum = currentCardNameChecksum;
                currentCardNameChecksum = AutoItX.PixelChecksum(currentCard);

                lastCardSetChecksum = currentCardSetChecksum;
                currentCardSetChecksum = AutoItX.PixelChecksum(setPosition);

                ocr.AddToCollectionImage(currentCard, numberPosition, setPosition);
                AutoItX.Send(Constants.DownArrow);

                if (++i < cardLocations.Count)
                {
                    currentCard = cardLocations[i].Copy();
                    setPosition.MoveTopEdgeTo(currentCard.TopEdge);
                    setPosition.MoveBottomEdgeTo(currentCard.BottomEdge);
                    numberPosition.MoveTopEdgeTo(currentCard.TopEdge);
                    numberPosition.MoveBottomEdgeTo(currentCard.BottomEdge);
                }
                else
                {
                    AutoItX.Sleep(slowDownAmount);
                }
            }

            return SplitCombinedImageFile(ocr, true);
        }
 public static int PixelChecksum(Square area)
 {
     return PixelChecksum(area.LeftEdge, area.TopEdge, area.RightEdge, area.BottomEdge, 1);
 }