Mine Hunter

Allan Struthers Ma2990

Introduction

Minehunter is a simple logic-based computer game. Versions come shipped free with most versions of Windows, Linux and Mac OS.  A rectangular grid is filled with a specified number of hidden mines.  The aim of the game is to discover the location of all the mines by uncovering the squares.  Clicking on a square terminates the game if it is mined and uncovers the square and shows the total number of mines in the adjacent squares.  Most versions have an option to automatically expose all the clearly safe squares adajcent to squares with no adjacent mines.

Mine sweeper on wiki

Questions

The questions we hope to address for various grid-sizes and mine-counts are:

Is the game automatically safely completable?

Given a game configuration how likely is a given square to be mined.

How likely is it to be able to safely complete a game given optimal play.

How likely is it to be able to complete a game given optimal play.

What are the best starting squares?

more

Variations

How does the game change if:

You do not know the number of mines

The information provided is the total number of mines in the vertically and horizontally adjacent squares.

The games is played on a periodic domain in the horizontal and vertical directions

The games is played on a periodic domain in the horizontal direction.

Simulation

A game board is represented as an appropriately dimensioned matrix of 0s and 1s. 0s are safe and 1s are mined. The information to be exposed is generated by summing adjacent squares in the game board matrix

RandomGame[n1_,n2_,m_]:= Module[
{M},
M= Join[ ConstantArray[1,m],ConstantArray[0,n1*n2-m]];
M=RandomSample[M];
Partition[M,n2]
]

This is not quite finished. We should fix it.

AdjacentCounts[M_]:= Module[
{AC=0*M,n1,n2},
{n1,n2}=Dimensions[M];
Do[
AC[[i,j]]=M[[i-1,j]]+M[[i+1,j]]+
M[[i,j+1]]+M[[i,j-1]]+
M[[i+1,j+1]]+M[[i+1,j-1]]+
M[[i-1,j+1]]+M[[i-1,j-1]],
{i,2,n1-1},
{j,2,n2-1}
];
AC
]

Testing

M=RandomGame[4,5,8];
AC=AdjacentCounts[M];
{MatrixForm[M],MatrixForm[AC]}

There are Math things for all sorts of stuff e.g.

ListConvolve[{{1,1,1},{1,0,1},{1,1,1}},M]