bild
School of
Electrical Engineering
and Computer Science

Artificiel intelligence, ai08
The minesweep agent project

Introduction

Background

Your team is trying to get a very lucrative deal to develop a system for clearing mine fields. However, before you are given access to the real hardware you have to prove yourself in simulation. The strategy you come up with will be tested in the classical minesweep game for which a typical environment is shown below.

In this game all squares are initially unknown and you have to open them one by one. The game is over if you open a square with a mine under. You will be evaluated on how many squares you managed to open without being blown up. When you open a square you will be told how many mines are in the 8-neighbors of that square but not where they are. Your task is to use the knowledge you have gained in the AI course to come up with a strategy to clear the minefield in a good way, i.e. without getting blown up.

Rules overview

Since when opening the first square there is no information available and an explosion at this point can not be blamed on your AI system, the game will be considered started after the first non-mine square has been opened. Your team will get one point per cleared square. If you trigger a mine it will cost you $c_{dead}$. You also have the option to use a new piece of hardware the allows you to peek at the content of a square before deciding what to do. This will cost you $c_{peek}$ and you can do this only once, but it will give you the same information as if you had opened the square but you do not risk getting killed. You can decide to stop and collect the points that you have earned so far at any time.

Evaluation and testing

To evaluate the performance of your agent you can define minefield in files and play one at a time or in batch mode. The mine files have the following format
00000000000000000000000
00000000000010000000000
00000000010000000000000
00000000000000000000000
Here the ``0'' denote squares that are free from mines and ``1'' means that there is a mine in that place. There is no requirement that the area is square (number of rows and columns the same) but each row/column has the same length.

Software

The system you develop should be able to communicate with the Minesweep server (Minesweep.java) provided in source.

Help classes

An interface for a MineAgent is provided in JAVA and C++ to move the focus away from programming and towards the AI part of the task. There is also a program called MineClient.java/MineClient.cc that can connect to and communicate with the server. What you have to do is to inherit from the MineAgent interface/baseclass and implement the functions
  • startNewGame(...)
    Called once in the beginning of the game
  • getNextMove()
    Called every time you should make a move
  • handleInfo(...)
    Called every time there is new information for you, such as when a square was opened
These functions are automatically called for you when you run the MineClient program.

You are free to implement your agent in any language you want and you do not have to use the code provided here. If you want to be able to compare it with other agents easily though it helps if it can communicate with the Minesweep server.

Downloads

Here you can download the code provided for this project
  • The java code contains the server (needed by all) and the JAVA interface and client code to connect to the server.
    • Version from 2008-08-31 (Thanks to Oscar Sundbom ai07 for your fixes!)
  • The c++ code contains a base class for an agent and client code that can connect to the server.
  • To evaluate your agent and during debugging it is often useful to run on specific board configurations. You can run in so called batch mode.
    • The batch file used in a single player game in 2007 batch file 2007
    • The batch file used in a single player game in 2006 batch-qual-2006.zip
    • An agent from 2006 can be found here agent2006.jar . You run it with
      java -jar agent2006.jar
      
      It is based on the MineClient.java class so you can give it the same arguments.

Running the code

To test the code that was provides simply build the java code and start the server. Have a look at the menu in the server and you will find that there are a number of different modes and settings. You can for example run with random boards, you can load a board at a time and you can load whole batch files (see above). As a first test do this
  1. Go into the java source directory
  2. Do "javac *.java"
  3. In one window do "java Minesweep"
  4. In another window do "java MineClient"
  5. Press "New game"

Batch mode

To test using a batch file unzip the batch file above in the server directory and select to run from batch file in the menu and select the file ending with .msb. The server will create log file with the results of the games. This files will be called for example
batchresults-Wawi's-2008-08-31_15-12-13.633.txt
for an agent called Wawi's.
NOTE if the *.msb file that was contained in the batch file does not show up in the file chooser you have put it in the wrong directory.

You can also start a batch fie server thanks for Oscar Sundbom from ai07. This allows you to start a server that will automatically start the game on a batch file specified when starting the batch server. This is quite convenient when evaluating many different settings for example. To start the batch server do

java Batchsweep batchfile.msb [Port] [NumPlayers]
where the batchfile is the .msb file like above (must be there) and the port and number of players are optional arguments.

Task

  • Design and implement a strategy for minesweeping.
  • Investigate how effective the strategy is for different amounts of mines, sizes of the environment, etc. What about the complexity?
  • How does the cost for detonating a mine and peeking affect the strategy?
  • How does the strategy change if you have another agent on the field?
  • Gather statistics to support your claims about the effectiveness.
  • What if you know before hand how many mines there are in the field? Would that change the strategy?
  • What if the minesweep cannot fly around, i.e.~you are only allowed to move to squares near to where you are standing. The first square you can still choose freely? How does this change the problem?

Using the provided code

Notice that this code is provided for your convenience. There are no guarentees that it is without bugs. It is likely to help those of you who do not want to spend too much time on coding though. If you find bugs please report them or even better provide bug fixes like Oscar last year.
Copyright © Published by: Patric Jensfelt <patric@csc.kth.se>
Updated 2008-10-03