AutoHotkey Community

It is currently May 27th, 2012, 10:19 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Minesweeper Auto-Solver
PostPosted: June 23rd, 2007, 3:33 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Enjoy!

Old code:
Code:
;
; AutoHotkey Version: 1.0.47.00
; Language:       Anyone
; Platform:       Windows XP with XP theme enabled
; Author:         Fincs <fernandoincs@hotmail.com>
;
; Script Function:
;   Minesweeper auto-solver
;

; Results
; =======

; Nascent:         2 sec.
; Intermediate:      4 sec.
; Advanced:         8 sec.

level := 1   ; 1 - nascent, 2 - intermediate, 3 - advanced

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.

; Process level
level ++
If level = 2         ; Nascent
   c := 9            ; 9 columns
If level = 3         ; Intermediate
   c := 16            ; 16 columns
If level = 4         ; Advanced
   c := 30, r := 16   ; 30 columns, 16 rows

If r =
   r := c

Run, winmine   ; Execute Minesweeper
Sleep, 100
WinGetActiveTitle, title   ; Get the title of Minesweeper
WinMove, %title%,, 80, 80   ; Move the window to the position 80, 80
Send, {ALT}{DOWN %level%}{ENTER}   ; Select level
Sleep, 10
Send, xyzzy{LShift}      ; Enter cheat code
Sleep, 10

CoordMode, Mouse, Relative

; Define constants
x = 21
y = 111
sum = 16

Loop, %r%
{
   d := 0
   Loop, %c%
   {
      MouseMove, %x%, %y%      ; Move the mouse to the next square
      Sleep, 10
      PixelGetColor, color, -80, -80   ; Check the color of the first pixel
      If color <> 0x000000
         Click   ; The pixel says "secure"
      x += sum
      d ++
   }
   x = 21
   y += sum
}


New code:
Code:
;
; AutoHotkey Version: 1.0.47.00
; Language:       Anyone
; Platform:       WinXP with XP theme enabled
; Author:         Fincs <fernandoincs@hotmail.com>
;
; Script Function:
;   Minesweeper auto-solver
;

; Results
; =======

; Nascent:         2 sec.
; Intermediate:      4 sec.
; Advanced:         8 sec.

level := 3   ; 1 - nascent, 2 - intermediate, 3 - advanced
sleep := 1   ; 0 - no sleep when mouse is clicked, 1 - sleep

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetMouseDelay -1 ; Do the mouse operations immediately

; Process level
level ++
If level = 2         ; Nascent
   c := 9            ; 9 columns
If level = 3         ; Intermediate
   c := 16            ; 16 columns
If level = 4         ; Advanced
   c := 30, r := 16   ; 30 columns, 16 rows

If r =
   r := c

Run, winmine,,, pid   ; Execute Minesweeper
WinWait, ahk_pid %pid%
IfWinNotActive,,, WinActivate
WinWaitActive
WinMove,,, 80, 80   ; Move the window to the position 80, 80
Send, {ALT}{DOWN %level%}{ENTER}   ; Select level
Sleep, 10
Send, xyzzy{LShift}      ; Enter cheat code
Sleep, 10

CoordMode, Mouse, Relative

; Define constants
x = 21
y = 111
sum = 16

Loop, %r%
{
   d := 0
   Loop, %c%
   {
      MouseMove, %x%, %y%, 0      ; Move the mouse to the next square
      PixelGetColor, color, -80, -80   ; Check the color of the first pixel
      If color <> 0x000000
         Click   ; The pixel says "secure"
      If sleep
         Sleep, 10
      x += sum
      d ++
   }
   x = 21
   y += sum
}
WinWait, ahk_pid %pid%
IfWinNotActive,,, WinActivate
WinWaitActive

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Last edited by fincs on June 27th, 2007, 10:25 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2007, 3:43 am 
Offline

Joined: October 30th, 2006, 10:17 pm
Posts: 43
Code:
;


level :=


Gui, Add, Button, x6 y10 w110 h30 gbutton1, Easy
Gui, Add, Button, x6 y50 w110 h30 gbutton2, Intermediate
Gui, Add, Button, x6 y90 w110 h30 gbutton3, Advanced

;Guicontrol, -Disable, MinimizeBox



Gui, Show, x257 y110 h130 w125, Minesweeper auto-solver
Return

button1:
gui, hide
level := 1
goto, here
return

button2:
gui, hide
level := 2
goto, here
return

button3:
gui, hide
level := 3
goto, here
return

here:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.

; Process level
level ++
If level = 2         ; Nascent
   c := 9            ; 9 columns
If level = 3         ; Intermediate
   c := 16            ; 16 columns
If level = 4         ; Advanced
   c := 30, r := 16   ; 30 columns, 16 rows

If r =
   r := c


Run, winmine   ; Execute Minesweeper
me:
Sleep, 300
IfWinActive, ahk_class Minesweeper,,,
{
BlockInput,Mouse
BlockInput,on
WinMove, ahk_class Minesweeper,, 80, 80   ; Move the window to the position 80, 80
Send, {ALT}{DOWN %level%}{ENTER}   ; Select level
Sleep, 10
Send, xyzzy{LShift}      ; Enter cheat code
Sleep, 10

CoordMode, Mouse, Relative

; Define constants
x = 21
y = 111
sum = 16

Loop, %r%
{
   d := 0
   Loop, %c%
   {
      MouseMove, %x%, %y%      ; Move the mouse to the next square
      Sleep, 10
      PixelGetColor, color, -80, -80   ; Check the color of the first pixel
      If color <> 0x000000
         Click   ; The pixel says "secure"
      x += sum
      d ++
   }
   x = 21
   y += sum
}
BlockInput,off
exitapp
}
else
{
;msgbox, try again
goto, me
;GuiClose:
;exitapp
}
return

_________________
Tex© Click here to mail me


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2007, 10:51 am 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Hi, Justineo14

I tried your version and the class of Minesweeper is different for each language. I'm using the spanish version of Windows XP and the class of Minesweeper is "Buscaminas" and the title is the same.
Quote:
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Buscaminas
ahk_class Buscaminas

>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen: 368, 179 (less often used)
In Active Window: 288, 99

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<

Color: 0xD8E9EC (Blue=D8 Green=E9 Red=EC)

>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: 80 top: 80 width: 170 height: 259

>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<

>>>>>>>>>>>( Hidden Window Text )<<<<<<<<<<<

>>>>( TitleMatchMode=slow Visible Text )<<<<

>>>>( TitleMatchMode=slow Hidden Text )<<<<


For that reason my version captures the window title of Minesweeper.
Anyway, thanks for the GUI!

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2007, 9:39 pm 
Offline

Joined: September 14th, 2006, 1:47 pm
Posts: 31
Hi fincs

I made a little diffrent version.

With this u play like "normal" ;)
But...
If u Leftclick on a bomb it rightclicks instead....
and if u rightclick where there is no bomb it leftclicks.

So u are guaranteed to solve it ;)

EDIT: new code below....

Code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
CoordMode, Pixel, screen    ;So that pixelgetcolor,0,0 is upper left pixel of the screen

Gui -AlwaysOnTop -caption
Gui, Color, 0000FF
Gui Show, w1 h1 x0 y0, blocker    ;creates a blue "pixel" using a window

Run, winmine,,, pid
WinWait, ahk_pid %pid% ; wait for the new window to exist
WinActivate, ahk_pid %pid% ; activate it
Send, xyzzy{LShift}      ; Enter cheat code

#X::exitapp   ; Win+X close the script if needed

#IfWinActive, ahk_class Minesweeper   ;Left Button only active when minesweeper is
LButton::
#IfWinActive, ahk_class Minesweeper   ;Right Button only active when minesweeper is
RButton::
mousegetpos,StartXX, StarYY
if (StartXX<>EndXX AND StartYY<>EndYY){  ;makes sure the mouse has moved to avoid errors
  PixelGetColor, color, 0, 0   ; Check the color of the first pixel
  If color = 0x000000
    send {RButton}
  If color = 0xFFFFFF
    send {LButton}
  If color = 0xFF0000
  {
    send {LButton Down}         
    keywait LButton
    send {Lbutton up}
  }
  winset,Redraw,,blocker  ;the cheat never redraw the 0,0 pixel.... will be latest color even if u close winmine.
}
 mousegetpos, EndXX, EndYY
Return
Return


If u want to impress with nice times on the "ScoreBoard" all the times and names etc are stored cleartext in the registry so its easy to modify:
HKEY_CURRENT_USER\Software\Microsoft\Winmine\

would be easy to make an ahkscript to edit the scoreboard ;)


///Ricke


Last edited by ricke on June 28th, 2007, 4:09 pm, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2007, 3:41 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
So how does it work...? By checking some cheat pixel? It'd be a whole lot more interesting if it (tried) to solve it by using only what the user sees...

Still, I managed to get the times of fincs' script down to 1 second (the absolute minimum!) for every difficulty. 8)

First, put this anywhere above the Loop
Code:
SetMouseDelay, -1

Second, comment out the sleep in the loop:
Code:
;Sleep, 10

Third, use speed 0 for MouseMove (this one seems to make only a minor difference, on Advanced, after the other two):
Code:
MouseMove, %x%, %y%, 0

:twisted:

By the way, it might be more reliable if you used the process ID and WinWaitActive. For example:
Code:
Run, winmine,,, pid ; puts the ID of the new winmine process in "pid"
WinWaitActive, ahk_pid %pid% ; wait for the new window to be active

Or to be even more reliable (in case running winmine doesn't always activate it):
Code:
Run, winmine,,, pid
WinWait, ahk_pid %pid% ; wait for the new window to exist
WinActivate, ahk_pid %pid% ; activate it


One last comment... "solve" and "complete via cheats" are two very different things. :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 4:44 am 
Offline

Joined: July 22nd, 2007, 4:42 am
Posts: 3
This is awesome!! I've seen times like these and knew there had to be something to do with automation.


Question, is there a way to do this with no windows popping up and then enter a name? so like i could make an auto run on my flash drive and whatever comp I stuck it into it would do this and post my name (or a message I put in) as the high score?

great work though i love cheating it intrigues me


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 5:50 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
rammrodd wrote:
so like i could make an auto run on my flash drive and whatever comp I stuck it into it would do this and post my name (or a message I put in) as the high score?
If all you want is your name in the high scores, edit
Code:
HKEY_CURRENT_USER\Software\Microsoft\winmine\Name*
HKEY_CURRENT_USER\Software\Microsoft\winmine\Time*
in the registry. Minesweeper high scores are recorded seperately for each user, though...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2007, 7:00 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
lexikos wrote:
So how does it work...? By checking some cheat pixel? It'd be a whole lot more interesting if it (tried) to solve it by using only what the user sees...

Indeed. That would be very impressive. It would be quite do-able though, just alot of work. The logic involved is fairly simple. ImageSearch for squares with numbers. Count the neighboring marked mines (ImageSearch) again. Count the neighboring unexplored squares. If marked mines = Number then explore any neighboring unexplored squares. If marked mines + unexplored squares = Number then mark all unexplored squares as mines.

Somewhat harder would be programing it to make the best guess in cases where there was no clear correct choice.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Autosweep
PostPosted: July 26th, 2007, 7:40 am 
Offline

Joined: July 18th, 2007, 5:45 am
Posts: 151
Location: South Florida
Good morning!

If you do a search for a program called "Autosweeper" you will find a minesweeper solver that actually solves it versus using a cheat code and pixel shade tricks.

If you turn guessing on, it will attempt to solve the full puzzle and will muck up sometimes when it has to guess.

On my machine, it averages about 75-80 seconds to do the expert minefield.

1900 lines of code make it migraine-inducing but to this newbie autohotkey programmer, it definitely is interesting.

Have a nice day!
Thrillski


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2007, 8:40 am 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Thrillski wrote:
to this newbie autohotkey programmer

Who is this AHK programmer? Me? (note that I have 1 year with AHK) Or you? I don’t know.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Autosweep
PostPosted: July 26th, 2007, 9:28 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Thrillski wrote:
to this newbie autohotkey programmer, it definitely is interesting.
fincs wrote:
Who is this AHK programmer? Me? (note that I have 1 year with AHK) Or you? I don’t know.
I'm sure Thrillski wouldn't know whether you found it interesting or not...


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Autosweeper
PostPosted: July 26th, 2007, 2:19 pm 
Offline

Joined: July 18th, 2007, 5:45 am
Posts: 151
Location: South Florida
The poster of the Autosweeper is bhao. I figured that if you actually did the search, the author would be discovered.

Have a nice day!
Thrillski


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Won't Work on Vista
PostPosted: January 4th, 2009, 12:18 pm 
Offline

Joined: January 4th, 2009, 11:15 am
Posts: 4
This code or the cheat for that matter will not work on Vista :(

Ref:http://erpman1.tripod.com/current/winmine.htm

Basically the current version of Minesweeper on Vista has no known cheats.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Won't Work on Vista
PostPosted: January 4th, 2009, 12:30 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
outspoken wrote:
Basically the current version of Minesweeper on Vista has no known cheats.
That would make it worth playing.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 11th, 2009, 7:01 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Look at this, how big boys attack the problem...
http://www.youtube.com/watch?v=LHY8NKj3RKs


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], specter333, XX0 and 25 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group