HOME

Automine

By Andy Hou
Automine is a program written in Java that will automatically play Windows Minesweeper.
// TODO(andyehou): Applet version coming soon.

  • Click to download Automine.
  • Screenshots
  • Usage Instructions
  • How Automine Interacts with Windows Minesweeper
  • How Automine Plays Minesweeper
  • Screenshots
    Automine wins easily on beginner.


    Automine wins most of the time on intermediate.


    Automine rarely wins on expert.
    Usage Instructions
    Before you use Automine you should first make sure that you have the Java Runtime Environment installed on your computer. To check this, click on Start->Run and type "cmd" and then press [ENTER] to bring up the command prompt. Then at the command prompt, type "java -version" without the quotes. If the Java Runtime Environment installed, then you should see a message saying what version is installed. Check that the version is 1.5 or higher. If it is not installed or the version is less than 1.5, you can install the latest version by going
    here and following the instructions.

    To use Automine, first download it here, and save the file automine.jar somewhere on your hard disk. Then bring up a command prompt and go to the directory where you saved the file (if you are unfamiliar with the command prompt, there is a good beginning tutorial here). Type "java -jar automine.jar" without the quotes to run Automine. Automine will start Windows Minsweeper and play one game.

    You can have Automine do other things by providing command line arguments. You can have Automine display a description of these by typing "java -jar automine.jar -h". The other arguments are:

    -g gamesTells Automine how many games you want it to play. Defualt is 1. For example, use "java -jar automine.jar -g 10" to have Automine play 10 games in a row.
    -d delaySets the delay between mouse clicks in milliseconds. Default is 10. For example, use "java -jar automine.jar -d 1000" to have Automine wait 1 second between clicks.
    -w waitSets the time to wait between games in milliseconds. Default is 5000. For example, use "java -jar automine.jar -w 10000" to have Automine wait 10 seconds between games.

    Any combination of these arguments in any order can be given to Automine. If you want Automine to play at a different difficulty setting, simply adjust the setting directly in Windows Minesweeper. Windows Minesweeper should remember what setting it is on the next time it is started. Automine will automatically determine the size of the board and play it.

    Warning
    Automine takes control over mouse movement while it is playing a game. It is recommended that you do not set the delay between games too small so that you have time to kill Automine between games if you want to.
    How Automine Interacts with Windows Mindesweeper
    Windows Minesweeper doesn't have an interface that a program can use to directly interact with it, so Automine must do this just as you or I would play minesweeper. Automine looks at the screen to determine the current board position and it moves and clicks the mouse to indicate its next move.

    Luckily, Java provides a class that makes all this easy to do. The Robot class provides methods that let a program move the mouse, click the mouse, and take screenshots.

    When Automine starts, it must determine the position of the minesweeper board on the screen. It does this by taking a screenshot and then searching the screen in a checkerboard fashion for a group of pixels that looks like a minesweeper tile. Once it has found a match, it then looks at neighboring pixels to determine the size of the board. When Automine needs to rescan the board, it knows the position and size of the board already and it simply looks at each tile to determine what type of tile it is. In all, Automine needs to be able to distinguish between the 12 different kinds of tiles shown below. You can notice that it is possible to do this just by looking at a few carefully selected pixels per tile.



    Since Automine looks at screenshots to determine the position of the minesweeper board on the screen, it can become confused if you have things that looks like minesweeper boards on the screen (such as images of minesweeper boards). Automine expects that the board does not move on the screen, so it can also become confused if the board does get moved.
    How Automine Plays Mindesweeper
    The algorithm that Automine uses to play minesweeper is very simple. In pseudocode it looks like this:
    
    while the board is not solved and a mine has not exploded
        // Try to flag as many tiles possible with 100% certainty.
        for each tile in the board that is marked with a number
            count the number of neighboring tiles that are blank
            count the number of neighboring tiles that are flagged
            if the number of blank + flagged neighbors equals the number marking this tile then
                flag each neighboring tile that is blank
            endif
        endfor
    
        // Try to click a tile with 100% certainty.
        for each tile in the board that is marked with a number
            count the number of neighboring tiles that are blank
            count the number of neighboring tiles that are flagged
            if the number of flagged neighbors equals the number marking this tile and
                the number of blank neighbors is greater than 0 then
                click each neighboring tile that is blank
                break out of the for loop
            endif
        endfor
    
        if no tile was clicked then
            select a random tile and click it
        endif
    
        update the board position by taking a screenshot
    endwhile
    
    
    The algorithm basically flags as many tiles as it can with 100% certainty, then clicks on a tile with 100% certainty or if this is not possible it clicks randomly, then updates the board and repeats until the board is solved or a mine explodes.

    Here is an example of when automine can flag the blank tiles with 100% certainty.


    Here is an example of when automine can click the blank tiles with 100% certainty.


    Of course, it is possible to have Automine win more games with a more complicated algorithm, but this will have to wait until a later version.

    Last updated: January 19, 2006
    HOME