Jump to content
Sign in to follow this  

Minesweeper bot

Recommended Posts


Using winapi memory reading :)

only works in xp (or less maybe)

#include <Winapi.au3>

Global Const $DataPtr = 0x1005330
Global Const $MinesPtr = 0x1005340
Global $MineSweeper_PID = Run("winmine.exe") ;run it
Global $hProcess = _WinAPI_OpenProcess(0x1F0FFF, 1, $MineSweeper_PID, True) ;open it

dim $read

WinWait("Minesweeper") ;wait for the minesweeper to load.

$DataStruct = DllStructCreate("dword mines;dword width;dword height")
_WinAPI_ReadProcessMemory($hProcess, $DataPtr, DllStructGetPtr($DataStruct), DllStructGetSize($DataStruct), $read) ;Get widht, height and number of mines :)

ConsoleWrite(DllStructGetData($DataStruct, "mines") &  " Mines in a  " & DllStructGetData($DataStruct, "width") & " by " & DllStructGetData($DataStruct, "height") &  " grid " & @CRLF)


$Width = DllStructGetData($DataStruct, "width") - 1
$Height = DllStructGetData($DataStruct, "height") - 1

For $y = 0 To $Height
    For $x = 0 To $Width
        Switch _IsMine($x,$y)
            Case -1 ;Already open
            Case 0 ;Safe to click on
                ControlClick("Minesweeper", "", "", "left", 1, 20 + ($x *16),(16 * $y) + 60)
            Case 1 ;MINE!!!!
                ControlClick("Minesweeper", "", "", "right", 1, 20 + ($x *16),(16 * $y) + 60)
        ;Sleep(25) ;Looks cool :P

Func _IsMine($x, $y)
    $buffer = DllStructCreate("ubyte mine")
    _WinAPI_ReadProcessMemory($hProcess, $MinesPtr + (32 * ($y + 1)) + ($x + 1) , DllStructGetPtr($buffer), DllStructGetSize($buffer), $read)
    If DllStructGetData($buffer, "mine") = 0x40 Then
        Return -1
    ElseIf DllStructGetData($buffer, "mine") = 0x0F Then
        Return 0
    ElseIf DllStructGetData($buffer, "mine") = 0x8f Then
        Return 1

[font="Impact"]Never fear, I is here.[/font]

Share this post

Link to post
Share on other sites

HeHe nice job m8 ^^

it plays better than me >_<

Share this post

Link to post
Share on other sites

Nice >_<.

How of curiosity, who did you figure out how to use the dll file? I mean I know what they do, but how do you know what the... (for lack of a better word choice) stuff in it does?

And the sleep(25) is neccissary if you're trying to solve an Expert puzzle :(. Else it goes too fast for it.


Share this post

Link to post
Share on other sites

doesn't work in Vista >_<

lol i don't even think Minesweeper is installed on vista..

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.