//排雷操作 static bool DeMine(ref Pieces board) { bool sthDone = false; int[] positionsAround; int[] 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].NumOfMines != 0 && board.board[i, j].NumOfFlags == board.board[i, j].NumOfMines) { positionsAround = board.RoundPoints(i, j); 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 && vis[point[0], point[1]] == false) { Click(point[0], point[1]); vis[point[0], point[1]] = true; sthDone = true; //Thread.Sleep(50); } } } } } return(sthDone); }
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); }
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); }