How Cellular Automaton Plays Minesweeper - Science Direct

5 downloads 0 Views 583KB Size Report
The most known is a Life game discussed for two and ... game board that do not contain mines, and you mark the squares that do contain mines. .... we have at time t = 0 one open site (with no neighboring mines) being at one of the corners of ...
Ii NOgl~ - I-]OUAND

How Cellular A u t o m a t o n Plays Minesweeper Andrew Adamatzky

Biophysics Department St. Petersburg State University Kubinskaya Street 56-64 St. Petersburg, Russia

ABSTRACT The Windows Minesweeper game seems to be known to almost all who use personal computers. Mines are distributed inside the bounded room, and empty sites are filled with ciphers, indicating how many neighboring mines exist. At the start of a game we have all mines hidden and wish to mark them all. We construct a two-dimensional deterministic cellular automaton which marks all mines populated on the n × n size lattice in ~ ( n ) time. Every cell of this automaton has 25 closest neighbors including itself and 27 states. © Elsevier Science Inc., 1997

" K n o w i n g when to mark a square as a mine is the key to

winning the game." - - H e l p . Section, " M a r k i n g a S q u a r e " 1.

INTRODUCTION

S o p h i s t i c a t e d progress in t h e V L S I t e c h n o l o g y has r e a t t r a c t e d interest of t h e wide scientific c o m m u n i t y to t h e m a s s i v e l y parallel c o m p u t i n g implem e n t e d on t h e processors w i t h cellular a u t o m a t a architecture. I t p r o v i d e s a chance t o b u i l d u p a correct t h e o r y of cellular a u t o m a t a algorithms, whereas d a t a as c o m p u t e r s are e m b e d d e d in t h e s a m e space. Using identification t h e o r y of cellular a u t o m a t a (dealing w i t h how to r e c o n s t r u c t local t r a n s i tions rules from t h e global s n a p s h o t s of a u t o m a t o n evolution), we designed several n o n t r i v i a l a l g o r i t h m s for t h e p r o b l e m s of c o m p u t a t i o n a l g e o m e t r y [1]. T h e y are t h e so-called w a v e a n d reaction-diffusion a l g o r i t h m s where waves o r i g i n a t i n g from d a t a sources s p r e a d a r o u n d lattice, react w i t h each

APPLIED MATHEMATICSAND COMPUTATION85:127-137(1997) © Elsevier Science Inc., 1997 655 Avenue of the Americas, New York, NY 10010

0096-3003/97/$17.00 PII S0096-3003(96)00117-8

128

A. ADAMATZKY

other and form stationary structures in the result of interaction. Distribution of data on the lattice is an input and final stationary structures are the outputs. We demonstrated that cellular a u t o m a t a algorithms can be used efficaciously in the constructing convex hull [2], discrete Voronoi diagram [3]. Moreover, these algorithms were mapped on the structure of the chemical processors intended to approximate planar Voronoi diagram as described in an upcoming paper in Advanced Materials for Optics and Electronics. In this paper, we try to amalgamate the theory of cellular a u t o m a t a computations with cellular a u t o m a t a games. The most known is a Life game discussed for two and three dimensions in m a n y books and papers (see e.g., [4-6]). A simple combinatorial game of cellular a u t o m a t a origin is presented in [7]. Sutner analyzed the game when source configuration is transformed into target one by the sequence of local transformation (changing of the nodes states) of rectangular lattice [8]. Our attention was focused on the Minesweeper* game because most personal computers users are familiar with it. As it was said in the beginning of the Help " . . . playing Minesweeper you are presented with a mine field, and your objective is to locate all the mines as quickly as possible. To do this, you uncover the squares on the game board that do not contain mines, and you mark the squares that do contain mines. The trick is determining which squares are which". This is a formulation of the problem which will be solved by appropriate cellular automaton in the paper. RESULTS Let us recall what cellular a u t o m a t a are. A cellular automaton (CA) is the tuple A = (L, Q, u, f ) , where L is a d-dimensional lattice or array of n × n cells ( d t> 1), Q is a finite nonempty cell state set, u is a neighborhood (u: L --* Lk), and f is a cell state transition function (f: Qk ~ Q). In our case, we will use two-dimensional CA, d = 2. When we ask does the cell (site) contain a mine, we should analyze not only closest neighbors of this cell, but second-order neighbors as well. So, the neighborhood of cell x will consists of 25 cells (full neighborhood with radius 2 including central cell): ~ ( x ~ 3 ) = ( x i _ 2 ~ _ 2 , . . . , x i j , . . . , x~+2j+2), i, j = 1 , . . . , n. The state of a cell should indicate whether the cell contains a mine and, if not, how m a n y mines are around the cell. Therefore, cell state set will be a direct product Q = {-, # , o} × {0, 1 , . . . , 8}, where " x t -- # " means "it *Microsoft Windows Minesweepergame, © 1985-1992 Microsoft Corp., by R. Donner and C. Johnson.

Cellular Automaton and Minesweeper

129

became known at time t that cell x contains a mine"; " x t = o" means " a t time t site x becomes open"; " x t = ." means "site x is closed at time t", and figures 0, 1 , . . . , 8 indicate number of mines being in the closest ( x i _ i , j _ 1. . . . , x~+1,3+ 1) neighbors. So, duple ( x t , u(x)}, where x t ~ {., o, #} and u(x) ~ {0, 1 , . . . , 8}, determines the state of cell x at time step t. Moreover, neighbors of x will be able to know u(x) only when x' = o. When a h u m a n plays Minesweeper, he decides whether a site is mined or not, based on circumstantial facts about correlation between ciphers drawn in the neighboring open sites and numbers of mines around them. The deterministic player uncovers the site if he finds that there is at least one neighboring open site, cipher on which corresponds to the number of already marked mines, or there is a neighboring open site with zero cipher. If a player does not mean to uncover a site he m a y mark it by pointing on the mine. There is a straightforward way to detect a mine: the site is definitely mined if it is a single covered neighbor of such an uncovered site cipher on which there is more than a number of marked mines around. We offer the following rule for cell state transitions

o,

(~=.)

^ ( 3 y ~ ~,~(z): ¢ =

^ (~(y)

=

o

0 v ~(y) z~ ul(y)

xt+ 1

#, (x'=.)

^

(3ye \

~(x):

¢=

E

x(z ', ") : 1

zE ul(y) A u(y)--~ ze ul(y)

",

o ^

x(zt,#)r=l)

otherwise

where Ul( X0 = ( x~_ 1 j - l , " " , Xi: l j+l)~k xij, Ul( Xij) C U( Xij ). A condition for transition • --) corresponds (with some additions) to the first hint "If an uncovered square already has the correct number of adjacent mines marked, clear around it" ["Using Strategies and Hints", Help for Minesweeper]. Whereas, the useful hint " I f an uncovered square is labeled 1, and there is only one covered square touching it, that covered square must be a mine" can be expanded to the condition for transition The initial, covered in the whole play board, would not be acceptable by CA because it is unable to open any cell. So, at the first step of the game, we help CA and give him a mine field with some uncovered intact sites. Only

130

A. ADAMATZKY

zero-cipher sites from the given ones can be the sources for waves of uncovering. As shown in Figure 1, only two from three initially uncovered sites have no mines around (Figure 1, t = 0). These sites were a sources of the waves spreading in all directions. Starting as excitation or reaction-diffusion waves (Figure 1, t = 1, 2), waves of the uncovering change their shape with time (Figure 1, t = 3, 4, ... ) due to random distribution of the mines around the mine field. So the whole front of the wave becomes fractured as a coast line. A game is assumed to be finished when CA falls in the fixed point of its global evolution, i.e., configuration of it becomes stationary, c t+ 1 = c t, as at time t = 27, Figure 1. Beginning our discoursing, we assert that CA is deterministic: V w Q k 3 ! a ~ Q: ](w) = a. Contrary to a human player, CA does not make random moves and cannot uncover sites when the abovementioned conditions are not satisfied. Both this fact and nonperiodic boundary conditions lead to the situations when there are regions which cannot be opened. Really, the regions have such combination of the closed, opened, and marked sites on the boundaries that make it impossible to move (Figure 2). From the numerous computational experiments, we found that a situation when the field open in the whole has an island of uncovered sites, it has a very low probability. Rather (under the great ratio of mines) the game will be finished when tiny islands (originating from initially uncovered single sites) of the open and marked sites axe in the ocean of closed ones.

PROPOSITION 1. C A A f i n i s h e s M i n e s w e e p e r on a lattice o f n × n cells with all u n c o v e r e d or m a r k e d sites in ~ ( n) time. A wave of computations spreads with the unit velocity, therefore, when we have at time t = 0 one open site (with no neighboring mines) being at one of the corners of the lattice, the front of the uncovering reaches the opposite corner in ~ ( n ) time. Really, CA m a y come to the stationary configuration in much less time because of the appearing of some impassable barriers.

PROPOSITION 2. CA loses at one o f two M i n e s w e e p e r g a m e s w h e n any site o f lattice is m i n e d with probability m o r e than 0.15. Explanatory diagrams on Figures 3 and 4 present results of the experiments with CA playing Minesweeper under various probabilities of mine distribution. They display that critical probability of mine distribution is 0.10 - 0.16. In about half of the games, about half of the sites remain

Cellular Automaton and Minesweeper

t.O ..................................... . . . . . .......... . . . . . . . . . . . . . . . . . . . . . . . . .

131

t-3

t-~

t-O

1OOOOOO. . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1000000 . 0 . . . . . . . . . . . . . . . . . . . . . . . . . . 2100000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1012 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 01131.0. . . . . .

.............................................. 100011 . . . . . ................... 0 . . . . . . . . . . . . . . . . . . . . . . . . . . 10001].1 . . . . .............. i . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.1000001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1000001 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2110001 . . . .

1OOOOOOOOO. . . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

11OOOOOOO00OOO. . . . . . . . . .

. 1000000000 . . . . . . . . . . . . . . 2100000000 . . . . . . . . . . . . . 11:111001110 . . . . . . . . . . . . . 1.12110011101..2101 . . . . . . OOIZIO I ~=~n'+"I41ZOOO . . . . . . .O O O 0 1 ~ Z I Z O 0 1 1 D I O O O . . . . . . . 12100ZIZOOI2,ZO0001 . . . . .

. . . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

21+10001410.000 . 1ZOOOZ11000 111001:I~1121 . . 100000113 . . . 212.00012 . . I.IZOLl.22 . .

............................................................................

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . . . . . . . . . . . . . . . . .

. . . . . .

. . . . . .

. . . . . .

001110000000000431 .......... 001221000000000412 .......... 00014KI 11OO11ZOZ1313124KIO... O001121ZOOII2,01132Z01110... OO0001110122Z0;D11OOOO~... O00000OO011"IOOZ4DZOOOZIZ01. 011222100LI.ZOOZIZOOOOIIZO0.

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . .

221;1121211000ZIZO00000. 1112.3Z2ZIOOOLTZOOOOZ1. . . . . :11111OO000Z12111.. . . . . . 111100000ZI1311.1.. . . . . . 1Z,121ZOOOU. ;IIZ.. . . . . . OOOZIZ01..I.22 ......

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1001.2121

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

101241

........................................................................................................

101 . . . . . . . . . . . . .

t.1 . . . . . ......... ......... ......... . . . . . . . . . . . . . . .

tm4 . . . . . . . . . . . . . . . . . . . . . . . . . . 000 . . . . . . . . . . . . . . . . . . . OOO . . . . . . . . . . . . . . . . . . . 110 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

t.7 10000000 . . . . . . . . . . . . . . . . . . . . . . 1 0 0 0 0 0 0 0 0 0 0 10000000

. . . . . . . . . . . . . . . . . . . . . . 10000000000

t'lO . . . . . . . . . . . . . . . . . . . . . . . . . . . .

0002.1+1.0000000000000 0001110000000000012

......... .........

~IlooOOOO . . . . . . . . . . . . . . . . . . . . 1221000000000 . . . . . . . . . . . . . . 0 0 0 2 . 2 2 . 1 . 0 0 0 0 0 0 0 0 0 0 2 1 . . . . 4 1 . 1 . .

12110011 . . . . . . . . . . . . . . . . . . . . . 211001 . . . . . . . . . . . . . . . . . . . . . . . 11012 . . . . . . . . . . . . . . . . . . . . . . . 0001..OO2.~10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 0011100 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1100011 . . . . . . . . . . . . . .

..................

........ ...........

001 .........................

0112ZlOOZ;1Z01...31;I 01.12110011Z011321011 000Z.I.1013~I.0211Z0000 OO00000ZIIOOIlKIZOOQ1

. . . . .

22331OO2110012.%OOOO~ . .

IZ112Z21100011101ZZ

10001010 . . . . . . . . . . . . . . . . . . .

. . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

O00OOJI21100Z110113101Z,'IIDO0.. O0001221100ZI:I.oZI3210ZIZOO.. O¢

Suggest Documents