Class MineSweeper

java.lang.Object
org.jacop.examples.fd.ExampleFD
org.jacop.examples.fd.MineSweeper

public class MineSweeper extends ExampleFD
It models and solves Minesweeper problem.
Version:
4.8

This is a port of Hakan's MiniZinc model http://www.hakank.org/minizinc/minesweeper.mzn

which is commented in the (swedish) blog post "Fler constraint programming-modeller i MiniZinc, t.ex. Minesweeper och Game of Life" http://www.hakank.org/webblogg/archives/001231.html

See also

The first 10 examples are from gecode/examples/minesweeper.cc http://www.gecode.org/gecode-doc-latest/minesweeper_8cc-source.html

http://www.janko.at/Raetsel/Minesweeper/index.htm

http://en.wikipedia.org/wiki/Minesweeper_(computer_game)

Ian Stewart on Minesweeper: http://www.claymath.org/Popular_Lectures/Minesweeper/

Richard Kaye's Minesweeper Pages: http://web.mat.bham.ac.uk/R.W.Kaye/minesw/minesw.htm

Some Minesweeper Configurations: http://web.mat.bham.ac.uk/R.W.Kaye/minesw/minesw.pdf

  • Field Details

    • r

      int r
    • c

      int c
    • X

      public static final int X
      It represents the unknown value in the problem matrix.
      See Also:
    • game

      IntVar[][] game
    • mines

      IntVar[][] mines
    • problem

      public int[][] problem
  • Constructor Details

    • MineSweeper

      public MineSweeper()
  • Method Details

    • model

      public void model()
      Description copied from class: ExampleFD
      It specifies a standard way of modeling the problem.
      Specified by:
      model in class ExampleFD
    • searchSpecific

      public void searchSpecific(boolean recordSolutions)
      It executes special search with solution printing to present the solutions.
      Parameters:
      recordSolutions - specifies if the solutions should be recorded.
    • readFromArray

      public static int[][] readFromArray(String[] description)
      It transforms string representation of the problem into an array of ints representation.
      Parameters:
      description - array of strings representing the problem.
      Returns:
      two dimensional array of ints representing the problem.
    • problem1

      public static final String[] problem1()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problem2

      public static final String[] problem2()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problem3

      public static final String[] problem3()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problem4

      public static final String[] problem4()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problem5

      public static final String[] problem5()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problem6

      public static final String[] problem6()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problem7

      public static final String[] problem7()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problem8

      public static final String[] problem8()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problem9

      public static final String[] problem9()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problem10

      public static final String[] problem10()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problemTest

      public static final String[] problemTest()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problem_kaye_splitter

      public static final String[] problem_kaye_splitter()
      One of the possible MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • problems

      public static final String[][] problems()
      The collection of MineSweeper problems.
      Returns:
      description of the problem used by the function to create a constraint model.
    • readFile

      public static int[][] readFile(String file)
      Reads a minesweeper file. File format: # a comment which is ignored % a comment which also is ignored number of rows number of columns < row number of neighbours lines... >

      0..8 means number of neighbours, "." mean unknown (may be a mine)

      Example (from minesweeper0.txt) # Problem from Gecode/examples/minesweeper.cc problem 0 6 6 ..2.3. 2..... ..24.3 1.34.. .....3 .3.3..

      Parameters:
      file - it specifies the filename containing the problem description.
      Returns:
      the int array description of the problem.
    • main

      public static void main(String[] args)
      It executes the program to solve any MineSweeper problem. It is possible to supply the filename containing the problem specification.
      Parameters:
      args - the filename containing the problem description.