Programmers minesweeper

I’ve created a timewaster that plays another timewaster… what a waste of time…
this one was just an experiment with the Robot class… it plays Windows Minesweeper. Very quickly.

Here’s what i mean…

http://www.adam.com.au/kellyjones/YABB/mine.gif

That’s a screenshot of my minesweeper game after running this little program a few times.

what it does is ‘reads’ the screen, and plays the game by manipulating the mouse. it’s not a very clever algorithm, sometimes expert can take over 100 goes to get it right… sometimes less than 30… a lot of luck is involved

a word of warning before you use it… It will take control of your mouse and play until either

  1. it has won
  2. it has lost a specified number of games. the default is 10 games…
  3. it thinks you closed Minesweeper. (or otherwise loses track or visibility of the play field)

it performs real mouse pointer movement and clicks. i take no responsibility if the program causes harm to your pc by clicking on something it shouldn’t… it’s good at realising when the game is gone… but if your desktop looks like the game, then it might not realise if you close Minesweeper. (it tracks squares by looking at the colour of the pixels)

to run it, first start up Minesweeper. position it toward the top left of the screen (no need for precision), and make sure the whole window is visible. Then select a dificulty and run the appropriate batch file. (be sure to move it off of minesweeper if it appears on top of it).

Also, here are some examples of running it from the command line…
java MinePlayer e 20 (Expert game, 20 attempts)
java MinePlayer b 10 (Beginner game, 10 attempts)
java MinePlayer i 10 (Intermediate game, 10 attempts)
java MinePlayer c 12 15 10 (Custom game, width 12, height 15, 10 attempts)

You can grab the source, class and bat files (to play beginner, intermediate, or advanced games) here

  1. Pretty Cool!

Wow, awesome util! :wink:

The algorithm could be greatly improved though, there’re a lot of tricks that it doesn’t “know” about. It plays like a n00b! :stuck_out_tongue: ;D

Haha I did the EXACT SAME THING in C a few years ago. I actually wanted to make a Java version a while back, but never got around to it.

i agree it is an inefficient algorithm.

could this be used as the base of an AI competition? Plenty of room for improvement and its a simple enough task

basically to see who can write the algorithm that wins the most games and the quickest (say out of 1000)… the operation to re-scan the board, for example takes a fair chunk of time so eg. an optimal algo would minimize its reliance on that operation…

the data is represented as a 2D array of ints…

of course, seconds would be nowhere near accurate enouh to decide, so eg. printing the system time taken to complete would be used.

i could easily clean it up, have it take a runnable object for the algorithm, make getters and setters for the array, and make public the method that scans the whole board and one that just checks a single tile… that sort of thing, so that you can write a swappable algorithm is run by the program (minimizes cheating by changing stuff that shouldn’t be changed, and running the official tests would use the same framework)

i do know a couple of tricks…eg. where u have 121 next to a wall of unknowns, the block next to the 2 is always safe…

[quote=“JuddMan,post:5,topic:25052”]
Clean it up and I’m in. :wink:

Some guy proved that this game is turing complete on an infinite grid and an NP complete problem. Every game is not garunteed to be solvable.

link

What about caravel drod? It’s much better for AI.

no, of course u can’t guarantee a win. that’s the challenge.

it makes the competition less about speed and more about AI…
finding a clever way to minimize the need to guess, and when you must guess, choosing the least risky option…

there’s an applet that supposedly wins 60% of the expert games it plays, but it also generates the games itself…

it would be interesting if the algorithm worked as well on the real thing.

there are also tradeoffs you can make when updating the information, which would for example trade speed for accuracy etc…

i’ll tidy up the code, add comments etc. and make a standard way to access the functions then…

and see if i can organise a prize or two…