Sign in to follow this  
Followers 0
Bones8185

MineSweeper Beater

8 posts in this topic

#1 ·  Posted (edited)

:wacko2:

EDIT: I venture to say that this is the only program on the forum that actually plays minesweeper for real!! I rule :lmao: , I will be fixing my code and I would like any one to post an original code that will actually play the game properly and beat my weak times...

B:2

I:7

A:35

EDIT: I've been looking at other minesweeper programs and I have no how they even work, I modeled mine after the way it is played for real, I'm still looking for one that doesn't "cheat" (odd irony)

This doesn't deserve to be here, turn back now if you don't want to waste your time.

I made this right when I joined the forum, just started looking at it again, tried to clean it up, still very rusty.

It first chooses a few random clicks until it can logically continue to solve the little puzzle that is minesweeper.

Since every number that denotes the num of mines is a diff color It uses that and continues on and down up search pattern.

Works in any diff, and even custom. Still, can only logically solve. With advanced it can get you close and you have to finish most of the time by guessing.

My lil' Bot got: (couldn't find out how to make the little pic images)

Screen Shot

Forgive the crudeness I warned you.

:x

I know I need to do some thing about the long funcs, but they need to be there for it to know what boxes are surrounding it, i.e. the top left only has three and so on...

Any pointers in faster execution or just better scripting??

NOTE: in order for it to work properly you would need to change your desktop theme to classic(like my older comp that I scripted this on), XP window titles are fatter and mess up my pixel size calcs, sorry :unsure:

Lol, if your still even reading this, thanx! o:)

Note the hot keys too...

HotKeySet("{ENTER}", "scan")
HotKeySet("{SPACE}", "randclick")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{HOME}", "reload")

    WinMinimizeAll()

;get Minesweeper//////////////////////////////////////////////////////////////////
    If NOT WinExists("Minesweeper") Then
            Run("C:\WINDOWS\system32\winmine.exe")
            WinWaitActive("Minesweeper")
        Else
            WinActivate ("Minesweeper")
            WinWaitActive("Minesweeper")
    EndIf
;Have Minesweeper////////////////////////////////////////////////////////////////// 
    
    $size = WinGetPos("Minesweeper")
    $xstart = $size[0]+15
    $ystart = $size[1]+96
    $box    = 16

;Start////////////////////////////////////////////////////////////////////////////
    
    $n = 0
    $xx = $size[0]
    $yy = $size[1]
    
    Do
        randclick($n)
                
    Until $n = 2

    while 1 
    scan() ;findflaggables()
    wend

    
;finds if there are flaggables near.
    Func canflag($xv, $yv, $sum, $getnum)
        
        $size = WinGetPos("Minesweeper")
        
        If $xv = $size[0] + 15 Then;for leftest column
            If $yv = $size[1] + 96 Then;for top left box
                $sumF = getFstat($xv+16, $yv) + getFstat($xv+16, $yv+16) + getFstat( $xv, $yv+16)
                If $sumF = $getnum Then
                    cnf($xv+16, $yv)
                    cnf($xv+16, $yv+16)
                    cnf($xv, $yv+16)
                ElseIf $sum + $sumF = $getnum Then
                    fnf($xv+16, $yv)
                    fnf($xv+16, $yv+16)
                    cnf($xv, $yv+16)
                EndIf
            ElseIf $yv = $size[1] + $size[3] - 27 Then;for bottom left box
                $sumF = getFstat($xv+16, $yv) + getFstat( $xv, $yv-16) + getFstat( $xv+16, $yv-16)
                If $sumF = $getnum Then
                    cnf($xv+16, $yv)
                    cnf($xv, $yv-16)
                    cnf($xv+16, $yv-16)
                ElseIf $sum + $sumF = $getnum Then
                    fnf($xv+16, $yv)
                    fnf($xv, $yv-16)
                    fnf($xv+16, $yv-16)
                EndIf
            Else  ;the same for only left column
                $sumF = getFstat($xv+16, $yv) + getFstat($xv+16, $yv+16) + getFstat( $xv, $yv+16) + getFstat( $xv, $yv-16) + getFstat( $xv+16, $yv-16)
                If $sumF = $getnum Then
                    cnf($xv+16, $yv)
                    cnf($xv+16, $yv+16)
                    cnf($xv, $yv+16)
                    cnf($xv, $yv-16)
                    cnf($xv+16, $yv-16)
                ElseIf $sum + $sumF = $getnum Then
                    fnf($xv+16, $yv)
                    fnf($xv+16, $yv+16)
                    fnf($xv, $yv+16)
                    fnf($xv, $yv-16)
                    fnf($xv+16, $yv-16)
                EndIf
            EndIf   
        ElseIf $yv = $size[1] + 96 Then;for top row only
                If $xv = $size[0] + $size[2] - 27 Then;top right box
                $sumF = getFstat( $xv, $yv+16) + getFstat( $xv-16, $yv+16) + getFstat( $xv-16, $yv) 
                    If $sumF = $getnum Then
                        cnf($xv, $yv+16)
                        cnf($xv-16, $yv+16)
                        cnf($xv-16, $yv)
                    ElseIf $sum + $sumF = $getnum Then
                        fnf($xv, $yv+16)
                        fnf($xv-16, $yv+16)
                        fnf($xv-16, $yv)
                    EndIf
                Else
                $sumF = getFstat($xv+16, $yv) + getFstat($xv+16, $yv+16) + getFstat( $xv, $yv+16) + getFstat( $xv-16, $yv+16) + getFstat( $xv-16, $yv) 
                    If $sumF = $getnum Then
                        cnf($xv+16, $yv)
                        cnf($xv+16, $yv+16)
                        cnf($xv, $yv+16)
                        cnf($xv-16, $yv+16)
                        cnf($xv-16, $yv)
                    ElseIf $sum + $sumF = $getnum Then
                        fnf($xv+16, $yv)
                        fnf($xv+16, $yv+16)
                        fnf($xv, $yv+16)
                        fnf($xv-16, $yv+16)
                        fnf($xv-16, $yv)
                    EndIf
                EndIf
        ElseIf $xv = $size[0] + $size[2] - 27 Then;rightest column
                If $yv = $size[1] + $size[3] - 27 Then
                $sumF = getFstat( $xv-16, $yv) + getFstat( $xv-16, $yv-16) + getFstat( $xv, $yv-16) 
                    If $sumF = $getnum Then
                        cnf($xv-16, $yv)
                        cnf($xv-16, $yv-16)
                        cnf($xv, $yv-16)
                    ElseIf $sum + $sumF = $getnum Then
                        fnf($xv-16, $yv)
                        fnf($xv-16, $yv-16)
                        fnf($xv, $yv-16)
                    EndIf
                Else
                $sumF = getFstat( $xv, $yv+16) + getFstat( $xv-16, $yv+16) + getFstat( $xv-16, $yv) + getFstat( $xv-16, $yv-16) + getFstat( $xv, $yv-16)
                    If $sumF = $getnum Then
                        cnf($xv, $yv+16)
                        cnf($xv-16, $yv+16)
                        cnf($xv-16, $yv)
                        cnf($xv-16, $yv-16)
                        cnf($xv, $yv-16)
                    ElseIf $sum + $sumF = $getnum Then
                        fnf($xv, $yv+16)
                        fnf($xv-16, $yv+16)
                        fnf($xv-16, $yv)
                        fnf($xv-16, $yv-16)
                        fnf($xv, $yv-16)
                    EndIf
                EndIf
        ElseIf $yv = $size[1] + $size[3] - 27 Then;bottom row
                $sumF = getFstat($xv+16, $yv) + getFstat( $xv-16, $yv) + getFstat( $xv-16, $yv-16) + getFstat( $xv, $yv-16) + getFstat( $xv+16, $yv-16) 
                If $sumF = $getnum Then
                    cnf($xv+16, $yv)
                    cnf($xv-16, $yv)
                    cnf($xv-16, $yv-16)
                    cnf($xv, $yv-16)
                    cnf($xv+16, $yv-16)
                ElseIf $sum + $sumF = $getnum Then
                    fnf($xv+16, $yv)
                    fnf($xv-16, $yv)
                    fnf($xv-16, $yv-16)
                    fnf($xv, $yv-16)
                    fnf($xv+16, $yv-16)
                EndIf
        Else
                $sumF = getFstat($xv+16, $yv) + getFstat($xv+16, $yv+16) + getFstat( $xv, $yv+16) + getFstat( $xv-16, $yv+16) + getFstat( $xv-16, $yv) + getFstat( $xv-16, $yv-16) + getFstat( $xv, $yv-16) + getFstat( $xv+16, $yv-16) 
                If $sumF = $getnum Then
                    cnf($xv+16, $yv)
                    cnf($xv+16, $yv+16)
                    cnf($xv, $yv+16)
                    cnf($xv-16, $yv+16)
                    cnf($xv-16, $yv)
                    cnf($xv-16, $yv-16)
                    cnf($xv, $yv-16)
                    cnf($xv+16, $yv-16)
                ElseIf $sum + $sumF = $getnum Then
                    fnf($xv+16, $yv)
                    fnf($xv+16, $yv+16)
                    fnf($xv, $yv+16)
                    fnf($xv-16, $yv+16)
                    fnf($xv-16, $yv)
                    fnf($xv-16, $yv-16)
                    fnf($xv, $yv-16)
                    fnf($xv+16, $yv-16)
                EndIf
        EndIf
    EndFunc

;check box number after click
    Func getnum($x, $y)
        $color = PixelGetColor($x+9, $y+12)
        
        If $color = 12632256      Then;gray     0
            Return 0
        ElseIf $color = 255    Then;blue      1
            Return 1
        ElseIf $color = 32768     Then;Dkgreen  2
            Return 2
        ElseIf $color = 16711680  Then;Red  3
            Return 3
        ElseIf $color = 128 Then;Dkblue 4
            Return 4
        ElseIf $color = 8388608   Then ;Dkred   5
            Return 5
        ElseIf $color = 32896      Then;teal    6   
            Return 6
        ElseIf $color = 0      Then;MINE    END mine red16711680
            Return 0
        Else    
    ;Didn't get PixelGetColor HAVE 7 OR 8 Yet
            Return 3  ;if other return 3, just because (Forgot why i did that)
        EndIf
    EndFunc

;check if box is clicked if so 1
    Func getstat($x, $y)
        $color = PixelGetColor($x, $y)
        If $color = 8421504 Then    ;Gray already clicked...
            Return 0
        ElseIf $color = 16777215 Then ;White
        $color = PixelGetColor($x+9, $y+12)
            If $color = 0 Then      ;flagged
                Return 0
            Else
                Return 1
            EndIf
        EndIf
    EndFunc
    
;check if box is flagged if so 1
    Func getFstat($x, $y)
        $color = PixelGetColor($x, $y)
        If $color = 8421504 Then    ;Gray already clicked...
            Return 0
        ElseIf $color = 16777215 Then ;White
        $color = PixelGetColor($x+9, $y+12)
            If $color = 0 Then      ;flagged
        ;MsgBox(0, "not needed but it has a flagged near it all ready", "")
                Return 1
            Else
                Return 0
            EndIf
        EndIf
    EndFunc

;flag a not flagged
    Func fnf($x ,$y)
        $color = PixelGetColor($x, $y)
        If $color = 16777215 Then ;White
        $color = PixelGetColor($x+9, $y+12)
            If $color = 0 Then      ;flagged
        ;MsgBox(0, "not needed but it has a flagged near it all ready", "")
            Else
                MouseClick("Right", $x, $y, 1, 0)
            EndIf
        EndIf
        
    EndFunc

;Click a not flagged
    Func cnf($x ,$y)
        $color = PixelGetColor($x, $y)
        If $color = 16777215 Then ;White
        $color = PixelGetColor($x+9, $y+12)
            If $color = 0 Then      ;flagged
        ;MsgBox(0, "not needed but it has a flagged near it all ready", "")
            Else
                MouseClick("Left", $x, $y, 1, 0)
            EndIf
        EndIf
        
    EndFunc

;RANDOM clicks when stuck
    Func randclick(ByRef $n)
        $size = WinGetPos("Minesweeper")
        $xstart = $size[0]+15
        $ystart = $size[1]+96
        
        $xmines = ($size[2] - 26) / 16
        $ymines = ($size[3] - 107) / 16
        
        Do
            $i = 0
            $rx = Random (0, $xmines - 1, 1)
            $ry = Random (0, $ymines - 1, 1)
            
            If PixelGetColor(($rx * 16) + $xstart, ($ry * 16) + $ystart) = 16777215 Then
                If getNstat(($rx * 16) + $xstart, ($ry * 16) + $ystart) < 2 Then
                    If Not PixelGetColor(($rx * 16) + $xstart + 9, ($ry * 16) + $ystart + 12) = 0 Then
                        MouseClick("Left", ($rx * 16) + $xstart, ($ry * 16) + $ystart, 1, 0)
                        $i = 1
                        $getdanum = getnum(($rx * 16) + $xstart, ($ry * 16) + $ystart)
                        If $getdanum = 0 Then
                            $n = $n+1
                        EndIf
                        If PixelGetColor(($rx * 16) + $xstart + 9, ($ry * 16) + $ystart + 12) = 0 Then
                        reload()
                        $i = 0
                        $n = 0
                        EndIf
                    EndIf
                EndIf
            EndIf
        
        Until $i = 1
    
    EndFunc

;Scan through
    Func scan()
        $size = WinGetPos("Minesweeper")
        $xmines = ($size[2] - 26) / 16
        $ymines = ($size[3] - 107) / 16
        $xv = $size[0] + 15
        $yv = $size[1] + 96
        
        For $ycount = 0 To $ymines - 1  Step 1
            For $xcount = 0 To $xmines - 1 Step 1
                If PixelGetColor($xv + 16 * $xcount, $yv + 16 * $ycount) = 8421504 Then
                    $number = getnum($xv + 16 * $xcount, $yv + 16 * $ycount) 
                    If NOT $number = 0 Then
                        $thesum = getAstat($xv + 16 * $xcount, $yv + 16 * $ycount)
                        If $thesum > 0 Then
                            MouseMove($xv + 16 * $xcount, $yv + 16 * $ycount, 0)
                            canflag($xv + 16 * $xcount, $yv + 16 * $ycount, $thesum, $number)
                        EndIf
                    EndIf   
                EndIf
            Next
        Next
        
        For $ycount = $ymines - 1 To 0  Step -1
            For $xcount = $xmines - 1 To 0 Step -1
                If PixelGetColor($xv + 16 * $xcount, $yv + 16 * $ycount) = 8421504 Then
                    $number = getnum($xv + 16 * $xcount, $yv + 16 * $ycount) 
                    If NOT $number = 0 Then
                        $thesum = getAstat($xv + 16 * $xcount, $yv + 16 * $ycount)
                        If $thesum > 0 Then
                            MouseMove($xv + 16 * $xcount, $yv + 16 * $ycount, 0)
                            canflag($xv + 16 * $xcount, $yv + 16 * $ycount, $thesum, $number)
                        EndIf
                    EndIf   
                EndIf
            Next
        Next
        

    EndFunc

;find and flag
    Func getAstat($xv, $yv)
        $size = WinGetPos("Minesweeper")
        $sum = 0
        
        If $xv = $size[0] + 15 Then;for leftest column
            If $yv = $size[1] + 96 Then;for top left box
                $sum = getstat($xv+16, $yv) + getstat($xv+16, $yv+16) + getstat( $xv, $yv+16)
                Return $sum         
            ElseIf $yv = $size[1] + $size[3] - 27 Then;for bottom left box
                $sum = getstat($xv+16, $yv) + getstat( $xv, $yv-16) + getstat( $xv+16, $yv-16)
                Return $sum             
            Else  ;the same for only left column
                $sum = getstat($xv+16, $yv) + getstat($xv+16, $yv+16) + getstat( $xv, $yv+16) + getstat( $xv, $yv-16) + getstat( $xv+16, $yv-16) 
                Return $sum             
            EndIf   
        ElseIf $yv = $size[1] + 96 Then;for top row only
                If $xv = $size[0] + $size[2] - 27 Then;top right box
                $sum = getstat( $xv, $yv+16) + getstat( $xv-16, $yv+16) + getstat( $xv-16, $yv) 
                Return $sum             
                Else
                $sum = getstat($xv+16, $yv) + getstat($xv+16, $yv+16) + getstat( $xv, $yv+16) + getstat( $xv-16, $yv+16) + getstat( $xv-16, $yv) 
                Return $sum             
                EndIf
        ElseIf $xv = $size[0] + $size[2] - 27 Then;rightest column
                If $yv = $size[1] + $size[3] - 27 Then
                $sum = getstat( $xv-16, $yv) + getstat( $xv-16, $yv-16) + getstat( $xv, $yv-16) 
                Return $sum                 
                Else
                $sum = getstat( $xv, $yv+16) + getstat( $xv-16, $yv+16) + getstat( $xv-16, $yv) + getstat( $xv-16, $yv-16) + getstat( $xv, $yv-16)
                Return $sum                 
                EndIf
        ElseIf $yv = $size[1] + $size[3] - 27 Then;bottom row
                $sum = getstat($xv+16, $yv) + getstat( $xv-16, $yv) + getstat( $xv-16, $yv-16) + getstat( $xv, $yv-16) + getstat( $xv+16, $yv-16) 
                Return $sum             
        Else
                $sum = getstat($xv+16, $yv) + getstat($xv+16, $yv+16) + getstat( $xv, $yv+16) + getstat( $xv-16, $yv+16) + getstat( $xv-16, $yv) + getstat( $xv-16, $yv-16) + getstat( $xv, $yv-16) + getstat( $xv+16, $yv-16) 
                Return $sum
        EndIf
    EndFunc
    
;find and flag
    Func getNstat($x, $y)
        $size = WinGetPos("Minesweeper")
        $xv = $x
        $yv = $y
        $sum = 0
        
        If $xv = $size[0] + 15 Then;for leftest column
            If $yv = $size[1] + 96 Then;for top left box
                $sum = getnum($xv+16, $yv) + getnum($xv+16, $yv+16) + getnum( $xv, $yv+16)
                Return $sum         
            ElseIf $yv = $size[1] + $size[3] - 27 Then;for bottom left box
                $sum = getnum($xv+16, $yv) + getnum( $xv, $yv-16) + getnum( $xv+16, $yv-16)
                Return $sum             
            Else  ;the speal for only left column
                $sum = getnum($xv+16, $yv) + getnum($xv+16, $yv+16) + getnum( $xv, $yv+16) + getnum( $xv, $yv-16) + getnum( $xv+16, $yv-16) 
                Return $sum             
            EndIf   
        ElseIf $yv = $size[1] + 96 Then;for top row only
                If $xv = $size[0] + $size[2] - 27 Then;top right box
                $sum = getnum( $xv, $yv+16) + getnum( $xv-16, $yv+16) + getnum( $xv-16, $yv) 
                Return $sum             
                Else
                $sum = getnum($xv+16, $yv) + getnum($xv+16, $yv+16) + getnum( $xv, $yv+16) + getnum( $xv-16, $yv+16) + getnum( $xv-16, $yv) 
                Return $sum             
                EndIf
        ElseIf $xv = $size[0] + $size[2] - 27 Then;rightest column
                If $yv = $size[1] + $size[3] - 27 Then
                $sum = getnum( $xv-16, $yv) + getnum( $xv-16, $yv-16) + getnum( $xv, $yv-16) 
                Return $sum                 
                Else
                $sum = getnum( $xv, $yv+16) + getnum( $xv-16, $yv+16) + getnum( $xv-16, $yv) + getnum( $xv-16, $yv-16) + getnum( $xv, $yv-16)
                Return $sum                 
                EndIf
        ElseIf $yv = $size[1] + $size[3] - 27 Then;bottom row
                $sum = getnum($xv+16, $yv) + getnum( $xv-16, $yv) + getnum( $xv-16, $yv-16) + getnum( $xv, $yv-16) + getnum( $xv+16, $yv-16) 
                Return $sum             
        Else
                $sum = getnum($xv+16, $yv) + getnum($xv+16, $yv+16) + getnum( $xv, $yv+16) + getnum( $xv-16, $yv+16) + getnum( $xv-16, $yv) + getnum( $xv-16, $yv-16) + getnum( $xv, $yv-16) + getnum( $xv+16, $yv-16) 
                Return $sum
        EndIf
    EndFunc

;reload
    Func reload()           
            MouseClick("Left", $size[0] + $size[2] / 2, $size[1] + 70, 1, 0)
            Sleep(10)
    EndFunc
;Exit
    Func Terminate()
    Exit 0
    EndFunc
Edited by Bones8185

FileMove(".\Bones8185.newB", ".\Bones8185.adv")

Share this post


Link to post
Share on other sites



I don't see how a minesweeper bot is really useful. The fun of the game is to be stupid and do badly when you don't know how to play.

Share this post


Link to post
Share on other sites

This is glitchy but It did work once for me ON EXPERT and won in 5 seconds. Great job


[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Share this post


Link to post
Share on other sites

Damn, for a non-memory editing minesweeper bot, thats pretty damn nice!

GJ, but memory editing would be WAY more accurate

Share this post


Link to post
Share on other sites

my dad was not amused when he noticed his highscore on minesweeper was a litle owned :-) GREAT BOT !

Share this post


Link to post
Share on other sites

You mean VERY glitchy... Never Beat it once.

But Nice job anyways :whistle:;):P

Remembered to change from XP mode to Classic mode ?? Did the trick for me ;)

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

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  
Followers 0