Ejemplo n.º 1
0
 static void testPrint(ref Pieces board)
 {
     for (int i = 0; i < board.row; i++)
     {
         for (int j = 0; j < board.col; j++)
         {
             Console.Write(output(board.board[i, j].state));
         }
         Console.WriteLine();
     }
 }
Ejemplo n.º 2
0
        static bool randGo(ref Pieces board)
        {
            bool sthDone = false, firstTime = true;

            int[] positionsAround;
            int[] point = new int[2];
            for (int i = 0; i < board.row; i++)
            {
                for (int j = 0; j < board.col; j++)
                {
                    if (board.board[i, j].NumOfMines != 0)
                    {
                        if (firstTime)
                        {
                            firstTime = false;
                            point[0]  = i;
                            point[1]  = j;
                        }
                        else if (board.board[point[0], point[1]].NumOfPiecesLeft != 0 && board.board[i, j].NumOfPiecesLeft != 0 &&
                                 board.board[i, j].NumOfMinesLeft * board.board[point[0], point[1]].NumOfPiecesLeft
                                 < board.board[i, j].NumOfPiecesLeft * board.board[point[0], point[1]].NumOfMinesLeft)
                        {
                            point[0] = i;
                            point[1] = j;
                        }
                    }
                }
            }
            if (!firstTime)
            {
                positionsAround = board.RoundPoints(point[0], point[1]);
                for (int round = 0; positionsAround[round] != -1; round += 2)
                {
                    point[0] = positionsAround[round];
                    point[1] = positionsAround[round + 1];
                    if (board.board[point[0], point[1]].state == 0)
                    {
                        Click(point[0], point[1]);
                        sthDone = true;
                        break;
                    }
                }
            }
            if (!sthDone)
            {
                int[][] v   = new int[board.row * board.col][];
                int     top = 0;
                for (int i = 0; i < board.row; i++)
                {
                    for (int j = 0; j < board.col; j++)
                    {
                        if (board.board[i, j].state == 0)
                        {
                            v[top++] = new int[2] {
                                i, j
                            }
                        }
                    }
                }
                ;
                if (top > 0)
                {
                    top = new Random().Next(top);
                    Click(v[top][0], v[top][1]);
                }
            }
            return(sthDone);
        }
Ejemplo n.º 3
0
        static bool InEx(ref Pieces board)
        {
            bool sthDone = false;

            int[] positionsAround2;
            int[] pointB = new int[2], pointA = new int[2], point = new int[2];
            bool[,] vis = new bool[board.row, board.col];

            for (int i = 0; i < board.row; i++)
            {
                for (int j = 0; j < board.col; j++)
                {
                    if (board.board[i, j].state <= 8 && board.board[i, j].state >= 1)
                    {
                        positionsAround2 = board.RoundPoints(i, j, 2);
                        pointA[0]        = i;
                        pointA[1]        = j;
                        for (int round = 0; positionsAround2[round] != -1; round += 2)
                        {
                            pointB[0] = positionsAround2[round];
                            pointB[1] = positionsAround2[round + 1];
                            if (board.board[pointB[0], pointB[1]].state <= 8 && board.board[pointB[0], pointB[1]].state >= 1)
                            {
                                int[] A = pointA;
                                int[] B = pointB;

                                int[] positionsAroundA, positionsAroundB, positionsAroundC;
                                int[] ar = new int[2];
                                int[] br = new int[2];
                                int   a  = board.board[A[0], A[1]].NumOfPiecesLeft,
                                      b  = board.board[B[0], B[1]].NumOfPiecesLeft,
                                      c,
                                      al = board.board[A[0], A[1]].NumOfMinesLeft,
                                      bl = board.board[B[0], B[1]].NumOfMinesLeft,
                                      clMax, clMin;
                                positionsAroundA = board.RoundPoints(A[0], A[1]);
                                positionsAroundB = board.RoundPoints(B[0], B[1]);
                                positionsAroundC = new int[17];
                                int top = 0;
                                for (int roundA = 0; positionsAroundA[roundA] != -1; roundA += 2)
                                {
                                    ar[0] = positionsAroundA[roundA];
                                    ar[1] = positionsAroundA[roundA + 1];
                                    if (ar[0] != -2 && board.board[ar[0], ar[1]].state == State.PIECEUP)
                                    {
                                        for (int roundB = 0; positionsAroundB[roundB] != -1; roundB += 2)
                                        {
                                            br[0] = positionsAroundB[roundB];
                                            br[1] = positionsAroundB[roundB + 1];
                                            if (br[0] != -2 && board.board[br[0], br[1]].state == State.PIECEUP)
                                            {
                                                if (ar[0] == br[0] && ar[1] == br[1])
                                                {
                                                    positionsAroundC[top++]      = ar[0];
                                                    positionsAroundC[top++]      = ar[1];
                                                    positionsAroundB[roundB + 1] = positionsAroundB[roundB] = -2;
                                                    positionsAroundA[roundA + 1] = positionsAroundA[roundA] = -2;
                                                }
                                            }
                                        }
                                    }
                                }
                                positionsAroundC[top++] = -1;
                                c     = top / 2;
                                clMax = Math.Min(Math.Min(al, bl), c);
                                clMin = Math.Max(Math.Max(al - (a - c), bl - (b - c)), 0);
                                if (clMax == clMin)
                                {
                                    int cl = clMax;
                                    if (a - c == al - cl)
                                    {
                                        for (int roundC = 0; positionsAroundA[roundC] != -1; roundC += 2)
                                        {
                                            point[0] = positionsAroundA[roundC];
                                            point[1] = positionsAroundA[roundC + 1];
                                            if (point[0] != -2 && board.board[point[0], point[1]].state == 0 && vis[point[0], point[1]] == false)
                                            {
                                                Click(point[0], point[1], true);
                                                // board.board[point[0], point[1]].state = 10;
                                                vis[point[0], point[1]] = true;
                                                sthDone = true;
                                                //Thread.Sleep(50);
                                            }
                                        }
                                    }
                                    if (al == cl)
                                    {
                                        for (int roundC = 0; positionsAroundA[roundC] != -1; roundC += 2)
                                        {
                                            point[0] = positionsAroundA[roundC];
                                            point[1] = positionsAroundA[roundC + 1];
                                            if (point[0] != -2 && board.board[point[0], point[1]].state == 0 && vis[point[0], point[1]] == false)
                                            {
                                                Click(point[0], point[1]);
                                                vis[point[0], point[1]] = true;
                                                sthDone = true;
                                                //Thread.Sleep(50);
                                            }
                                        }
                                    }
                                    if (c == cl)
                                    {
                                        for (int roundC = 0; positionsAroundC[roundC] != -1; roundC += 2)
                                        {
                                            point[0] = positionsAroundC[roundC];
                                            point[1] = positionsAroundC[roundC + 1];
                                            if (board.board[point[0], point[1]].state == 0 && vis[point[0], point[1]] == false)
                                            {
                                                Click(point[0], point[1], true);
                                                // board.board[point[0], point[1]].state = 10;
                                                vis[point[0], point[1]] = true;
                                                sthDone = true;
                                                //Thread.Sleep(50);
                                            }
                                        }
                                    }
                                    if (cl == 0)
                                    {
                                        for (int roundC = 0; positionsAroundC[roundC] != -1; roundC += 2)
                                        {
                                            point[0] = positionsAroundC[roundC];
                                            point[1] = positionsAroundC[roundC + 1];
                                            if (board.board[point[0], point[1]].state == 0 && vis[point[0], point[1]] == false)
                                            {
                                                Click(point[0], point[1]);
                                                vis[point[0], point[1]] = true;
                                                sthDone = true;
                                                //Thread.Sleep(50);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(sthDone);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            int Case;

            while (true)
            {
                Console.WriteLine("hello?\ninput numbers for what you want:\n1.run the plug of winmine\n0.exit\n");
                Case = Convert.ToInt32(Console.ReadLine());
                bool  running   = false;
                int[] happyFace = new int[2];
                switch (Case)
                {
                case 1:
                    int row, col;
                    Console.WriteLine("please input the number of rows:");
                    row = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("please input the number of columns:");
                    col = Convert.ToInt32(Console.ReadLine());
                    Pieces board = null;
                    while (true)
                    {
                        board = init(row, col, ref happyFace);
                        if (!running)
                        {
                            Console.WriteLine("running!");
                        }
                        if (board == null)
                        {
                            Thread.Sleep(500);
                            board = init(row, col, ref happyFace);
                        }
                        if (board == null)
                        {
                            firstRow = 0;
                            firstCol = 0;
                            Console.WriteLine("faild...");
                            Console.WriteLine("input '1' for retry,\ninput '2' for restart,\ninput '0' for exit:\n");
                            int CaseWhenFaild = Convert.ToInt32(Console.ReadLine());
                            running = false;
                            if (CaseWhenFaild == 1)
                            {
                                continue;
                            }
                            else if (CaseWhenFaild == 2)
                            {
                                break;
                            }
                            else if (CaseWhenFaild == 0)
                            {
                                return;
                            }
                        }
                        else
                        {
                            running = true;
                        }
                        if (board.CalNums() == false)
                        {
                            if (happyFace[0] == 0)
                            {
                                Console.WriteLine(0);
                            }
                            else
                            {
                                Click(happyFace[0] + 15, happyFace[1] + 15, false, true);
                            }
                            continue;
                        }
                        // testPrint(ref board);
                        bool sthDone = Flag(ref board);
                        sthDone = DeMine(ref board) || sthDone;
                        if (!sthDone)
                        {
                            if (!InEx(ref board))
                            {
                                randGo(ref board);
                            }
                        }
                    }
                    break;

                case 0:
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 5
0
        static Pieces init(int row, int col, ref int[] happyFace)
        {
            Pieces   board     = new Pieces(row, col);
            int      width     = Screen.PrimaryScreen.Bounds.Width;
            int      height    = Screen.PrimaryScreen.Bounds.Height;
            Bitmap   screenCut = new Bitmap(width, height);
            Graphics Front     = Graphics.FromImage(screenCut);

            Front.CopyFromScreen(0, 0, 0, 0, Screen.AllScreens[0].Bounds.Size);
            Front.Dispose();

            LockBitmap baseScreen = new LockBitmap(screenCut);

            baseScreen.LockBits();

            LockBitmap tmp = null;
            bool       Catch, catchTmp;

            Catch = false;
            int  rBegin = 0, cBegin = 0;
            bool begin = false;

            if (firstRow == 0)
            {
                for (int faceRound = 14; faceRound < 19; ++faceRound)
                {
                    tmp = new LockBitmap(State.index[faceRound]);
                    tmp.LockBits();
                    for (int r = 0; r < height; r++)
                    {
                        for (int c = 0; c < width; c++)
                        {
                            if (26 + c < width && 26 + r < height)
                            {
                                catchTmp = true;
                                for (int rr = 0; rr < 26; rr += 2)
                                {
                                    for (int cc = 0; cc < 26; cc += 2)
                                    {
                                        if (tmp.GetPixel(cc, rr) != baseScreen.GetPixel(cc + c, rr + r))
                                        {
                                            catchTmp = false;
                                            break;
                                        }
                                    }
                                    if (!catchTmp)
                                    {
                                        break;
                                    }
                                }
                                if (catchTmp)
                                {
                                    happyFace[0] = board.happyFace[0] = r;
                                    firstRow     = r + 40;
                                    happyFace[1] = board.happyFace[1] = firstCol = c;
                                    begin        = true;
                                    tmp.UnlockBits();
                                    break;
                                }
                            }
                        }
                        if (begin)
                        {
                            break;
                        }
                    }
                    if (begin)
                    {
                        if (faceRound == 14)
                        {
                            break;
                        }
                        else
                        {
                            Click(happyFace[0] + 15, happyFace[1] + 15, false, true);
                            System.Threading.Thread.Sleep(50);
                            Click(happyFace[0] + 15, happyFace[1] + 15, false, true);
                            break;
                        }
                    }
                    tmp.UnlockBits();
                }
                if (!begin)
                {
                    tmp.UnlockBits();
                    //Console.WriteLine("line 76");
                    return(null);
                }
                for (int r = firstRow; r < height; r++)
                {
                    for (int c = cBegin; c < width; c++)
                    {
                        if (16 + c < width && 16 + r < height)
                        {
                            for (int i = 0; i < 14; i++)
                            {
                                tmp = new LockBitmap(State.index[i]);
                                tmp.LockBits();
                                catchTmp = true;
                                for (int rr = 0; rr < 16; ++rr)
                                {
                                    for (int cc = 0; cc < 16; ++cc)
                                    {
                                        if (tmp.GetPixel(cc, rr) != baseScreen.GetPixel(cc + c, rr + r))
                                        {
                                            catchTmp = false;
                                            break;
                                        }
                                    }
                                    if (!catchTmp)
                                    {
                                        break;
                                    }
                                }
                                if (catchTmp)
                                {
                                    firstRow = r;
                                    firstCol = c;
                                    Catch    = true;
                                    tmp.UnlockBits();
                                    break;
                                }
                                tmp.UnlockBits();
                            }
                        }
                        if (Catch)
                        {
                            break;
                        }
                    }
                    if (Catch)
                    {
                        break;
                    }
                }
                if (!Catch)
                {
                    //Console.WriteLine("line 122");
                    return(null);
                }
            }
            int Row = 0, Col = 0;

            for (int r = firstRow; r < height; r += 16)
            {
                for (int c = firstCol; c < width; c += 16)
                {
                    Catch = false;
                    for (int i = 0; i < 14; i++)
                    {
                        tmp = new LockBitmap(State.index[i]);
                        tmp.LockBits();
                        if (16 + c < width && 16 + r < height)
                        {
                            catchTmp = true;
                            for (int rr = 0; rr < 16; rr += 2)
                            {
                                for (int cc = 0; cc < 16; cc += 2)
                                {
                                    if (tmp.GetPixel(cc, rr) != baseScreen.GetPixel(cc + c, rr + r))
                                    {
                                        catchTmp = false;
                                        break;
                                    }
                                }
                                if (!catchTmp)
                                {
                                    break;
                                }
                            }
                            if (catchTmp)
                            {
                                board.board[Row, Col].state = i;
                                Catch = true;
                                tmp.UnlockBits();
                                break;
                            }
                        }
                        tmp.UnlockBits();
                    }
                    if (Catch)
                    {
                        ++Col;
                    }
                    else
                    {
                        break;
                    }
                }
                ++Row;
                if (Row == row)
                {
                    break;
                }
                if (Col != col)
                {
                    //Console.WriteLine("line 172");
                    //screenCut.Save("C:\\Users\\dell\\Desktop\\172.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                    return(null);
                }
                Col = 0;
            }
            if (Row != row)
            {
                //Console.WriteLine("line 179");
                return(null);
            }

            board.row = Row;
            board.col = Col;

            return(board);
        }