Jump to content

Minesweeper Bot for Vista/XP/2000


RichRobot
 Share

Recommended Posts

Hi all,

I've written a bot that plays minesweeper.

The zip file contains 5 files

"Minesweeper XP Bot.au3", plays minesweeper on XP/2000. I haven't tested on 2000 but it should work

"Minesweeper Vista Bot", plays minesweeper on Vista. (built on the beta version of Vista minesweeper running on XP, so let me know if there are problems)

"Strategy.au3", determines the strategy the bots use, it is shared by the Vista and XP bot

"patterns.txt", is a set of patterns the bot watches for

"readme.txt", explains how to format the patterns.txt file

The bot plays much slower on Vista so I recommend the XP version.

Also uncommenting line 7 of Strategy.au3 will make the XP bot always win by cheating.

Edit: also need to comment out line 6 for cheat to work

************

Strategy of the bot is quite simple.

The makeSimpleMove() function searches for uncovered squares, determining the number of mines adjacent to them and the number of covered squares adjacent to them

If the $coveredAdjacent = $minesAdjacent then all surrounding squares are mines and can be marked as such.

If $minesAdjacent = 0 then all surrounding covered squares don't have mines and can be clicked

If the makeSimpleMove() function can't play then makeAdvancedMove() runs

Despite it's name advancedMove() isn't very advanced.

It only searches for patterns found in the patterns.txt file and then plays accordingly

If it can't find any of the patterns (which is likely). It simply plays the first covered square that doesn't have any uncovered squares or mines arround it.

If makeAdvancedMove() can't play then a random move is played using makeRandomMove()

******

The bots can often win on a beginners board, sometimes on intermediate and very seldom on expert.

Minesweeper is an NP-completeness problem so there is probably not an algorithm that can solve it quickly and correctly.

If you can build such an algorithm or prove that there is no such algorithm, it is worth a million dollors :P

Please send me suggestions. (or any patterns you've discovered)

Thanks to monoceres for help with the Vista Bot last night.

Hope you all enjoy

******

Edit: Changed the source of the XP bot so that it presses F2 when the game ends to start a new game. Thanks to pain for the sugestion. Also made the bot react to a win with a msgBox.

New Zip file attached to replace old.

Also noticed that bot sometimes flags mines that aren't mines, which means 1 of my patterns must be incorrect (or the pattern search itself). The pattern search algo is very much a jury rig, so I'll have to have a look it.

I'll work on internationalization tomorrow.

Edit 2: Fixed the pattern problem, the program was flaging mines whereever a u occured in the pattern when it was meant to be uncovering them. Realise this sounds a bit cryptic should be understandable after reading readme.txt

Updated the zip file again.

Minesweeper_Bots.zip

Edited by RichRobot
Link to comment
Share on other sites

Seems to work good on all three levels, had to modify it some because I'm not using a English version of XP.

Maybe a @OSLang would be good to make sure it will work at the beginning.

I also noticed you used WinClose if it failed, wouldn't it be better to send F2 instead?

Link to comment
Share on other sites

Seems to work good on all three levels, had to modify it some because I'm not using a English version of XP.

Maybe a @OSLang would be good to make sure it will work at the beginning.

I also noticed you used WinClose if it failed, wouldn't it be better to send F2 instead?

ERROr

@line 98

$square

variable used without being declared

Link to comment
Share on other sites

Hey thought, I'd post my best times

For XP they are 1 Second, 6 Seconds and 12 Seconds for beginner, intemediate and expert respectively. Let me know if you've beaten them.

My version of Vista's minesweeper doesn't store stats but I assume that if it did the times would be much slower. (I just ran it and it took 17 and then 9 seconds on beginner)

I think that commenting out the makeAdvancedMoves() function might make it play faster but less reliably (If you're going for a really quick time).

The randomMove() function can also be quite slow if its used near the end of a game, I'll have to work on it.

The bot still can't recognize anything above a 4 on Vista's board. If you see a 5, 6, 7, 8, and have the time, please let me know its colour.

XP needs the colours for 7 and 8 (I think these are really uncommon - so please post a screenshot if you happen to see one)

Edited by RichRobot
Link to comment
Share on other sites

1sec 4sec and 12 sec

$a=StringSplit("547275737420796F757220546563686E6F6C75737421","")
For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4)
Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI"
Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile;
MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-)
Link to comment
Share on other sites

7 and 8 isn't uncommon if you use "custom" game. try with this 24x24 and 529 mines and I can assure you will get 7 and 8 in a matter of 2-3 tries.

if not here is a screenshot

Posted Image

Thanks Pain, Got an 8 on the first click :P Very helpful

Unless I'm very lucky (only tried 5 times) it seems that the program might be cheating to ensure a mine isn't clicked on first go. Doesn't do that on standard levels. Requires further study. (I know for certain that Vista's minesweeper cheats on 1st click which means it is disallowed for competitive rankings.)

If anyone with Vista is reading this please check something for me. Open minesweeper, choose beginner level. Resize minesweeper and close it. Reopen minesweeper. Is it the original size or does it keep its attributes from before? I'm hoping to massively simplify the getBoardSize() function.

For those wondering why I'm building a bot for an operating system I don't have. It's for an article. I'm using Vista's Beta version of Minesweeper in XP, but its a bit buggy.

Link to comment
Share on other sites

In Windows, the Minesweeper board is generated randomly before the player clicks any squares. If the player happens to click a mine square on their very first click, the mine at this square is removed and a new mine is placed in the upper left corner. If there is already a mine in the upper left corner, a new mine is placed in the first (starting in the upper left corner then proceeding left->right, top->bottom) available empty spot of the board. Once this change is made, the game proceeds as if the initial clicked square was empty. This is done to ensure that the player will not lose on their very first click.

from:

http://en.wikipedia.org/wiki/Minesweeper_%28Windows%29

Link to comment
Share on other sites

Can't test it at the moment because I'm in Ubuntu but will trust you/wikipedia :P

I have a memory of losing on first clicks though and a website I read recently mentioned the Vista 1st click thing as a new feature. Oh well, memory can be wrong and the internets doubly so.

Thanks for all the help.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...