HHyperbolic Minesweeper is in P
Eryk Kopczy´nskiFebruary 25, 2020
Abstract
We show that, while Minesweeper is NP-complete, its hyperbolic vari-ant is in P. Our proof does not rely on the rules of Minesweeper, butis valid for any puzzle based on satisfying local constraints on a graphembedded in the hyperbolic plane. (a) graphical mode, bitruncated tessella-tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . . . (b) text mode, regular tessellation Figure 1: Hyperbolic Minesweeper [7]. In (a), the default settings are used(bitruncated order-3 heptagonal tessellation, numbers of adjacent mines arecolor-coded; some of the mines that the players is sure of are marked red). In(b) we play on an order-3 heptagonal tessellation, and numbers are shown.Minesweeper is a popular game included with many computer systems; italso exists in the puzzle form. In the puzzle form, every cell in a square grideither contains a number or is empty. The goal of the puzzle is to assign mines to1 a r X i v : . [ c s . CC ] F e b he empty squares in such a way that every number n is adjacent (orthogonallyor diagonally) to exactly n mines.This puzzle is a well-known example of a NP-complete problem [6]. Its pop-ularity has also spawned many variants played on different grids, from chang-ing the tessellation of the plane, to changing the number of dimensions (six-dimensional implementations of Minesweeper exist) to changing the underlyinggeometry.In this paper we will be playing Minesweeper on a tessellation of the hyper-bolic plane. Minefield, a land based on hyperbolic Minesweeper is available inHyperRogue [7]; this implementation differs from the standard Minesweeper inmultiple ways, e.g., by being played on an infinite board, however, the basic ideais the same. Another implementation is Warped Mines for iOS [13], which hasthe same rules as the usual Minesweeper except the board, which is a boundedsubset of the order-3 heptagonal tiling of the hyperbolic plane.From the point of view of a computer scientist, the most important distinc-tive property of hyperbolic geometry is exponential growth: the area of a circleof radius r grows exponentially with r . It is also more difficult to understandthan Euclidean geometry. While these properties often cause computationalgeometry problems to be more difficult, it also gives hyperbolic geometry appli-cations in data visualization [8, 9] and data analysis [10].In this paper we show that hyperbolic geometry makes Minesweeper easier:the hyperbolic variant of Minesweeper is in P. Our proof will not rely on thespecific rules of Minesweeper nor work with any specific tessellation of the hy-perbolic plane; instead, it will work with any puzzle based on satisfying localconstraints, on any graph that naturally embeds into the hyperbolic plane. We denote the hyperbolic plane with H . Since this paper requires only the basicunderstanding of hyperbolic geometry, we will not include the formal definition;see [2], or [7] for an intuitive introduction. Figure 1 shows the hyperbolic plane inthe Poincar´e disk model, which is a projection which represents angles faithfully,but not the distances: the scale gets smaller and smaller as we get closer to thecircle bounding the model. In particular, all the heptagons in Figure 1b are thesame size, all the heptagons in Figure 1a are the same size, and all the hexagonsin Figure 1a are the same size. We denote the distance between two points x, y ∈ H by δ ( x, y ). The set of points in distance at most r from x is denotedwith B ( x, r ). The area of B ( x, r ) is 2 π (cosh r − r ).The perimeter of B ( x, r ) is 2 π sinh r , which we denote with peri( r ). Note thatboth area and peri grow exponentially: area( r ) = Θ( e r ) and peri( r ) = Θ( e r ).2 Hyperbolic Graph
We need a suitable definition of a hyperbolic graph. The obvious definition,obtained by changing “plane” to “hyperbolic plane” in the definition of a planargraph, is equivalent to the definition of the planar graph (the plane and thehyperbolic plane are homeomorphic). Another definition found in literature isthe notion of Gromov δ -hyperbolic graph [1]; this definition is based on theobservation that, in the hyperbolic plane, triangles are thin, i.e., for any threevertices a , b , c , every point on any shortest path from a to c must be in distanceat most δ from either the shortest path from a to b , or the shortest path from b to c . The parameter δ measures tree-likeness of the graph (it can be easilyseen that trees are 0-hyperbolic). However, this definition is not suitable for us,because every graph G becomes 2-hyperbolic when we add a vertex v ∗ connectedto every v ∈ V ( G ); our main result is not true for such graphs. We propose thefollowing definition: Definition 3.1. A ( r, d ) - hyperbolic graph is a graph G = ( V, E ) such thatthere exists an embedding m : V → H such that: • for v (cid:54) = v , δ ( m ( v ) , m ( v )) > r , • for { v , v } ∈ E , δ ( m ( v ) , m ( v )) < d , • if we draw every edge { v , v } ∈ E as a straight line segment between m ( v ) and m ( v ) , these edges do not cross, nor they get closer to verticesother than v or v than r/ . This definition includes finite subsets of all regular and semiregular hyper-bolic tessellations (such as the ones shown in Figure 1). We denote N ( v ) to bethe neighborhood of v ∈ V , i.e., { v } ∪ { w ∈ V : { v, w } ∈ E } . (Our proof alsoworks with neighborhoods of larger radius.) Remark.
All ( r, d )-hyperbolic graphs have degree bounded by a constant(for fixed r, d ). Indeed, let v ∈ V . For every w ∈ N ( v ), the circles B ( w, r ) aredisjoint, and they fit in B ( v, d + r ). Therefore, | N | ≤ area( d + r ) / area( r ). Below we state our main result.
Theorem 4.1.
Fix the set of colors K and the parameters ( r, d ) . The follow-ing problem (Hyperbolic Local Constraint Satisfaction Problem, HLCSP) can besolved in polynomial time: INPUT: • a ( r, d ) -hyperbolic graph G = ( V, E ) ; • for every vertex v ∈ V , m ( v ) , a subset of K N ( v ) . UTPUT:
Is there a coloring c : V → K such that for every v ∈ V , c | N ( v ) ∈ m ( v ) ? HLCSP generalizes hyperbolic minesweeper. We have two colors (no mineand mine), and for every v ∈ V containing a number k , the constraint m ( v )says that v contains no mine itself, and exactly k of vertices in N ( v ) contain amine.To prove Theorem 4.1, it is enough to prove that the following problem(HECSP) is in P. Theorem 4.2.
HLCSP reduces to the Hyperbolic Edge Constraint SatisfactionProblem (HECSP) given as follows:
INPUT: • a ( r, d ) -hyperbolic graph G = ( V, E ) ; • for every edge e ∈ E , m ( e ) , a subset of K e . OUTPUT:
Is there a coloring c : V → K such that for every e ∈ E , c | e ∈ m ( e ) ?(Note: this reduction changes the set of admissible colors K .)Proof. Let (
G, m ) be the instance of HLCSP. We will be coloring V using colors K (cid:48) = { , . . . , k } , where k is the greatest number of elements of m ( v ) (since( r, d )-hyperbolic graphs have bounded degree and K is fixed, k is also bounded).Enumerate every elements of m ( v ) with one color from K (cid:48) . For e = { v , v } ∈ E , m ( e ) is the set of all colorings c : { v , v } → K which are consistent, i.e., k denotes c ∈ m ( v ) and k denotes c ∈ m ( v ), and c equals c on all thevertices in N ( v ) ∩ N ( v ). We will be using the following result [11, 3]:
Theorem 5.1.
Given a planar graph G = ( V, E ) and a number t , it is possibleto either find a t × t grid as a minor of G , or produce a tree decomposition of G of width ≤ t − , in time O ( n log( n )) , where n = | V | . Definition 5.2.
A tree decomposition of width w of a graph G = ( V, E ) is ( V T , E T , X ) where ( V T , E T ) is a tree, and X is a mapping which assign a subsetof V of cardinality at most w + 1 to every vertex in V T , such that: • For every v ∈ V , the set of vertices b ∈ V T such that v ∈ X b is connected, • For every e ∈ E , there exists a b ∈ V T such that es ⊆ X b . We can assume that our tree is rooted in r ∈ V T . For b ∈ V T , let X + b be theunion of X b (cid:48) for all b (cid:48) which are descendants of b .4 emma 5.3. Without loss of generality we can assume that every b ∈ V T fallsto one of the following cases: • b is a leaf and | X b | = 1 , • b has a single child b (cid:48) and X b (cid:48) = X b ∪ { v } , • b has a single child b (cid:48) and X b (cid:48) = X b − { v } , • b has two children b and b , X b = X b = X b , and X + b − X b and X + b − X b are non-empty and disjoint. Theorem 5.4.
If a ( r, d ) -hyperbolic graph G contains a t × t grid as a minor,then t = O (log( V ( G )) .Proof. Without loss of generality we can assume t = 2 k + 1. Such a t × t grid contains k cycles around the center of the grid. Let v c ∈ V be the vertexcorresponding to this center. We have k cycles C , . . . , C k in the graph V , eachof which surrounds v c and the preceding cycles. We use the following lemma: Lemma 5.5.
Every point in the drawing of cycle C i is in distance Ω( i ) from v .(The drawing is the polygon obtained as a union of the edges embedded in H .) Therefore, | C i | ≥ peri(Ω( i )) /d . Since peri grows exponentially, we get k = O log( | V | ). Proof of Lemma 5.5.
We will show that if every point in the drawing of C i is indistance at least x from v , then every point in the drawing of C i +1 is in distance x + c from v . By induction, this is enough to prove Lemma 5.5.Figure 2 shows what happens for an Euclidean graph. (We define Euclideangraph just like hyperbolic graph except the differing underlying geometry.) Inthis picture, the drawing of C i is a hexagon; cycle C i has six vertices around v c . For each of these seven vertices the exclusion zone of radius r/ v c h Figure 2: Cycles around v c C i +1 may fall into the gray/green region.All points in distance ≤ r/ C i fall in the gray/green region, thus ourclaim is true for c = h = r/ c = h 2, where h depends on r and d (we have h = Θ( re − d ) for large values of d ).Still, our claim holds with c > Corollary 5.6. Given a planar graph G = ( V, E ) , it is possible to find a treedecomposition of width O (log | V | ) in polynomial time.Proof. From Theorem 5.4 choose t = O (log | V | ) such that G does not containa k × k grid. From Theorem 5.1, it is possible to find a tree decomposition ofwidth 5 t − O (log | V | ). Corollary 5.7. HECSP (and thus HLCSP) can be solved in polynomial time.Proof. From Corollary 5.6 we can find a tree decomposition ( V T , E T , B ) of width w = O (log | V | ). Then we use Dynamic Programming over ( V T , E T ). For every b ∈ V T , we compute s ( w ), the set of all possible colorings c : X b ∈ K suchthat there exists a coloring c : X + b which extends c and which satisfies all theconstraints on edges in X + b . This can be computed straightforwardly in everycase from Lemma 5.3. The whole algorithm works in O ( | V | · | K | w ), which ispolynomial in | V | . We have shown that Minesweeper on hyperbolic tessellations can be solved inpolynomial time. Our method is general: it works for any ( r, d )-hyperbolicgraph, and for any problem based on satisfying local constraints. Other thansolving puzzles, this may be applied to procedural content generation. For exam-ple, the Wave Function Collapse (WFC) algorithm [4, 5] is used in procedurally (a) two yellow (b) one group (c) two groups (d) four groups Figure 3: Random colorings satisfying various constraints. Since the degree ofour polynomial is quite high, these pictures took about a minute to make. Somecells have been removed from the full disk to reduce the treewidth.6enerated games to procedurally generate maps satisfying local constraints (e.g.,a mountain should not appear close to ocean, or roads should not branch norend abruptly). In general finding out whether such constraints can be satisfiedis NP-complete (although this does not happen in typical PCG applications).Our algorithm can be adjusted to count the number of satisfying colorings, andto produce one of them, randomly chosen (Figure 3).Since the Euclidean plane can be embedded into a horosphere in three-dimensional hyperbolic space H , three-dimensional hyperbolic Minesweeper isNP-complete.HyperRogue also lets the player play Minesweeper in bounded hyperbolicmanifolds, such as the Klein quartic or other Hurwitz manifolds. Hurwitz man-ifolds are quotient spaces of H which can be tiled with regular heptagons withangles 120 ◦ (see Figure 1b), and that are maximally symmetric, i.e., there ex-ists an isometry of the Hurwitz manifold M into itself which map any heptagonwith any orientation into any heptagon with any orientation. Tessellations ofquotient space are no longer planar, thus Theorem 5.1 nor our proof of Theo-rem 5.4 is no longer valid in quotient spaces of H . Therefore, the complexityof Minesweeper on such manifolds does not follow from our results. Thereare less symmetric hyperbolic manifolds into which the Euclidean square grid,or even higher-dimensional Euclidean grids, can be embedded [12], and thusMinesweeper on them is NP-complete; however, highly symmetric manifoldshave a more restricted structure. References [1] Sergio Bermudo, Jos M. Rodrguez, Jos M. Sigarreta, and Jean-Marie Vi-laire. Gromov hyperbolic graphs. Discrete Mathematics , 313(15):1575 –1585, 2013. URL: , doi:http://doi.org/10.1016/j.disc.2013.04.009 .[2] James W. Cannon, William J. Floyd, Richard Kenyon, Walter, andR. Parry. Hyperbolic geometry. In In Flavors of geometry , pages 59–115. University Press, 1997. Available online at .[3] Alexander Grigoriev. Tree-width and large grid minors in planar graphs. Discrete Mathematics & Theoretical Computer Science , 13:13–20, 01 2011.[4] Maxim Gumin. WaveFunctionCollapse, 2017. https://github.com/mxgmn/WaveFunctionCollapse .[5] Isaac Karth and Adam M. Smith. WaveFunctionCollapse is ConstraintSolving in the Wild. In Proceedings of the 12th International Conferenceon the Foundations of Digital Games , FDG 17, New York, NY, USA, 2017.Association for Computing Machinery. doi:10.1145/3102071.3110566 .76] Richard Kaye. Minesweeper is np-complete. The Mathematical Intelli-gencer , 22(2):9–15, Mar 2000. doi:10.1007/BF03025367 .[7] Eryk Kopczy´nski, Dorota Celi´nska, and Marek ˇCtrn´act. Hyperrogue:Playing with hyperbolic geometry. In David Swart and Carlo H. S´equinand Krist´of Fenyvesi, editor, Proceedings of Bridges 2017: Mathematics,Art, Music, Architecture, Education, Culture , pages 9–16, Phoenix, Ari-zona, 2017. Tessellations Publishing. Available online at http://archive.bridgesmathart.org/2017/bridges2017-9.pdf .[8] John Lamping, Ramana Rao, and Peter Pirolli. A focus+context tech-nique based on hyperbolic geometry for visualizing large hierarchies. In Proceedings of the SIGCHI Conference on Human Factors in Comput-ing Systems , CHI ’95, pages 401–408, New York, NY, USA, 1995. ACMPress/Addison-Wesley Publishing Co. URL: http://dx.doi.org/10.1145/223904.223956 , doi:10.1145/223904.223956 .[9] Tamara Munzner. Exploring large graphs in 3d hyperbolic space. IEEEComputer Graphics and Applications , 18(4):18–23, 1998. URL: http://dx.doi.org/10.1109/38.689657 , doi:10.1109/38.689657 .[10] Fragkiskos Papadopoulos, Maksim Kitsak, M. Angeles Serrano, MarianBogu˜n´a, and Dmitri Krioukov. Popularity versus Similarity in GrowingNetworks. Nature , 489:537–540, Sep 2012.[11] N. Robertson, P. Seymour, and R. Thomas. Quickly excluding a pla-nar graph. Journal of Combinatorial Theory, Series B , 62(2):323 – 348,1994. URL: , doi:https://doi.org/10.1006/jctb.1994.1073 .[12] Zeno Rogue. HyperRogue: Experiments with Geometry, 2020. .[13] Sci-Tech Binary Ltd. Co. Warped mines, 2019. https://apps.apple.com/br/app/hypersweeper/id1450066199https://apps.apple.com/br/app/hypersweeper/id1450066199