Example #1
0
 public CellType getCellTYpe(Utils.MyRawBitmapData src, Utils.RECT rect)
 {
     BitmapSearch.BitmapSearchResult ret = cellTypeSearch.Search(src, rect, 2, 100);
     if (ret != null)
     {
         return(htJelly[ret.bitmap]);
     }
     return(CellType.Normal);
 }
Example #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            screen = new Bitmap("candycrush.png");
            Bitmap pngImage = new Bitmap("candycrush/ref.png");

            Utils.RECT rect  = Utils.RECT.fromInt(0, 0, screen.Width, screen.Height);
            long       start = System.Environment.TickCount;

            Utils.RECT scanRect = new Utils.RECT();
            scanRect.left   = rect.left;
            scanRect.top    = rect.top;
            scanRect.right  = (rect.left + rect.right) / 4;
            scanRect.bottom = (rect.top + rect.bottom) / 3;
            refPoint        = Utils.SmartFindBitmap(screen, scanRect, pngImage);
            if (refPoint.X == 0)
            {
                txtDebug.AppendText("Not found");
                return;
            }
            refPoint.X += 106;
            refPoint.Y += 69;

            Bitmap crop = Utils.cropImage(screen, new Rectangle(refPoint.X, refPoint.Y, cellW * NUMCELL, cellH * NUMCELL));

            Utils.RECT CELLRECT = Utils.RECT.fromInt(0, 0, cellW, cellH);
            for (int i = 0; i < NUMCELL; i++)
            {
                for (int j = 0; j < NUMCELL; j++)
                {
                    board.table[i, j] = null;
                    Rectangle cellRect = new Rectangle((i * cellW), (j * cellH), cellW, cellH);

                    Bitmap cropCell = Utils.cropImage(crop, cellRect);
                    Utils.MyRawBitmapData           cropCellBitmapData = new Utils.MyRawBitmapData(cropCell);
                    BitmapSearch.BitmapSearchResult searchRet          = candySearch.Search(cropCellBitmapData, CELLRECT, 2, 1000);
                    if (searchRet != null)
                    {
                        Point pRet = searchRet.point;
                        board.table[i, j] = htBmp[searchRet.bitmap].clone();
                        CellType ct = getCellTYpe(cropCellBitmapData, CELLRECT);
                        board.cell[i, j] = ct;
                    }
                }
            }
            long end = System.Environment.TickCount;

            dbgLine(refPoint + " " + (end - start));
            mainRect        = new Rectangle(refPoint.X, refPoint.Y, NUMCELL * cellW, NUMCELL * cellH);
            currentBestMove = board.getBestMove();
            lstResult       = board.getPossibleMove();
            imgMain.Refresh();
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            String title = "Candy Crush";

            Candy[,] table = board.table;
            Color[] refColors = new Color[] {
                Color.FromArgb(0xEBDEE4),
//                Color.FromArgb(235,223,228),
            };

            if (Utils.activateWindow(title))
            {
                screen = Utils.GetScreenShot();
                Bitmap     pngImage = new Bitmap("candycrush/ref.png");
                Utils.RECT rect     = new Utils.RECT();
                IntPtr     hwnd     = Utils.GetForegroundWindow();
                Utils.GetWindowRect(hwnd, out rect);

                long start = System.Environment.TickCount;
                txtDebug.AppendText("Active " + rect + " " + hwnd + "\n");
                Utils.RECT scanRect = new Utils.RECT();
                scanRect.left   = rect.left;
                scanRect.top    = rect.top;
                scanRect.right  = (rect.left + rect.right) / 4;
                scanRect.bottom = (rect.top + rect.bottom) / 3;
                refPoint        = Utils.SmartFindBitmap(screen, scanRect, pngImage);
                if (refPoint.X <= 0)
                {
                    txtDebug.AppendText("Not found");
                    return;
                }
                refPoint.X += 106;
                refPoint.Y += 69;

                mainRect = new Rectangle(refPoint.X, refPoint.Y, NUMCELL * cellW, NUMCELL * cellH);
                screen   = saveGetScreenShot(mainRect);
                screen.Save("candycrush.png");
                //Utils.MouseMove(refPoint.X, refPoint.Y);

                Bitmap     crop     = Utils.cropImage(screen, new Rectangle(refPoint.X, refPoint.Y, cellW * NUMCELL, cellH * NUMCELL));
                Utils.RECT CELLRECT = Utils.RECT.fromInt(0, 0, cellW, cellH);
                for (int i = 0; i < NUMCELL; i++)
                {
                    for (int j = 0; j < NUMCELL; j++)
                    {
                        board.table[i, j] = null;
                        Rectangle cellRect = new Rectangle((i * cellW), (j * cellH), cellW, cellH);

                        Bitmap cropCell = Utils.cropImage(crop, cellRect);
                        Utils.MyRawBitmapData           cropCellBitmapData = new Utils.MyRawBitmapData(cropCell);
                        BitmapSearch.BitmapSearchResult searchRet          = candySearch.Search(cropCellBitmapData, CELLRECT, 2, 1000);
                        if (searchRet != null)
                        {
                            Point pRet = searchRet.point;
                            board.table[i, j] = htBmp[searchRet.bitmap].clone();
                            CellType ct = getCellTYpe(cropCellBitmapData, CELLRECT);
                            board.cell[i, j] = ct;
                        }
                    }
                }
            }
            board.save("table.txt");
            board.load("table.txt");
            currentBestMove = board.getBestMove();
            lstResult       = board.getPossibleMove();
            imgMain.Refresh();
            //txtDebug.AppendText(table.ToString());
        }