• 大小: 64KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: Python
  • 标签:

资源简介

扫雷是个NP问题,自动扫雷系统(Python)。附有word报告说明文档。

资源截图

代码片段和文件信息

import ImageGrab
import os
import time
import win32api
import win32con
import random

# Important Globals
mines = [[-1 for x in xrange(16)] for x in xrange(30)] # tile definitions
mwid = 16 # width of tile in pixels
mhgt = 16 # height of tiles in pixels
thlf = 8 # convenient half heigh/width of tile (code should read easily!)
wypad = 0 # distance of window from top of screen
wxpad = 0 # distance of window from left of screen
ypad = wypad+104 # pixels from top of window to first tile boundary
xpad = wxpad+20 # pixels from left of window to first tile boundary
numGames = 99

#the operation of mouse
def leftClick():
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN00)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP00)

def rightClick():
    win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN00)
    win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP00)
    time.sleep(.1)

def moveMouse(xy):
    win32api.SetCursorPos((xy))

#grab the number
def grabMinesweeperWindow():
    boundingBox = (wxpad+0wypad+0wxpad+506wypad+367);
    mineWin = ImageGrab.grab(boundingBox)
    for x in xrange(30):
        for y in xrange(16):
            mines[x][y] = returnTileDefinition(mineWinxy)
    return mineWin

def returnTileDefinition(mineWinxy):

    if(mineWin.getpixel((xpad+thlf+mwid*xypad+thlf+mwid*y)) == (0 0 255)):
        return 1
    elif(mineWin.getpixel((xpad+thlf+mwid*xypad+thlf+mwid*y+4)) == (0 128 0)):
        return 2
    elif(mineWin.getpixel((1+xpad+thlf+mwid*xypad+thlf+mwid*y)) == (255 0 0)):
        return 3
    elif(mineWin.getpixel((2+xpad+thlf+mwid*xypad+thlf+mwid*y)) == (0 0 128)):
        return 4
    elif(mineWin.getpixel((xpad+thlf+mwid*xypad+thlf+mwid*y)) == (128 0 0)):
        return 5
    elif(mineWin.getpixel((xpad+thlf+mwid*xypad+thlf+mwid*y)) == (0 128 128)):
        return 6
    elif(mineWin.getpixel((xpad+thlf+mwid*xypad+thlf+mwid*y-3)) == (0 0 0)):
        if(mineWin.getpixel((xpad+thlf+mwid*xypad+thlf+mwid*y)) == (192 192 192)):
            return 7
        else:
            startNewGame() #mine restart
    elif(mineWin.getpixel((xpad+thlf+mwid*xypad+thlf+mwid*y)) == (163 6 4)):
        return 8
    elif(mineWin.getpixel((xpad+thlf+mwid*x4+ypad+thlf+mwid*y)) == (0 0 0)):
        if(mineWin.getpixel((xpad+thlf+mwid*xypad+thlf+mwid*y-2)) == (255 0 0)):
            return 9 #flag
        else:
            startNewGame() #mine restart
    elif(mineWin.getpixel((xpad+thlf+mwid*xypad+thlf+mwid*y)) == (192 192 192)):
        if(mineWin.getpixel((xpad+thlf+mwid*x-1ypad+2*thlf+mwid*y-1)) == (128 128 128)):
            return 10 #unopen
        else:
            return 0 #place without mine
    else:
        print “Somgthing is wrong!“ #others


def getNeighbor(xy):
    neighbor = {}
    for i in range(x-1x+2):
        for j in range(y-1y+2):
            if(i >=0 and i<30 and j<16 and j >=0):
                if(i!=x and j!= y):
                    neighbor[(ij)] = mines[i][j]

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       7498  2015-01-03 22:42  AutoMineSweeper\AutoMineSweeper.py

     文件     119808  2014-02-22 01:12  AutoMineSweeper\winmine.exe

     目录          0  2015-05-21 17:29  AutoMineSweeper

----------- ---------  ---------- -----  ----

               127306                    3


评论

共有 条评论

相关资源