Implementing L'OZ - CiteSeerX

16 downloads 0 Views 262KB Size Report
The objective of the game is to transform the initial (left) tiling into the final (right) ... Note that condition (u) implies that every vertex of a L'OZ tiling must be of the form ... 2) We translate directly in terms of M the effect of a L'OZ move. Once the .... In the second screen the player is offered a certain number of tilings of a zonogon ...
Implementing L’OZ A.P. Claudio 1 , I. P. F. da Silva2 , N. Pinto 3 , N. Prelhaz 3 , J. Soares

3

Abstract. L’OZ is a puzzle about tilings of polygons by lozenges. It is based on results of da Silva (93) and we have recently implemented a computer version of the game. We present the computer game and the mathematical and programming details of our implementation.

1

Faculdade de Ciˆencias da Universidade de Lisboa, Dep.to Inform´atica, Campo Grande, Edif´ıcio C6 - Piso 3, 1749-016 Lisboa, Portugal. E-mail: [email protected] 2 Faculdade de Ciˆencias da Universidade de Lisboa, Dep.to Matem´atica, Campo Grande, Edif´ıcio C6 - piso 2, 1749-016 Lisboa, Portugal. E-mail: [email protected] 3 Students of the De.pto Inform´atica of the Faculdade de Ciˆencias da Universidade de Lisboa. E-mails:(N. Pinto) nelson [email protected], (N. Prelhaz) [email protected], (J. Soares) [email protected]

1

1

Introduction

We start by describing L’OZ: In the screen the player is given two different lozenge tilings of the same polygon: the starting tiling - on the left and the final tiling, on the right.

Figure 1: A starting position of L’OZ The objective of the game is to transform the initial (left) tiling into the final (right) tiling, by using an appropriate sequence of moves. A move consists in clicking on a inner vertex of degree 3 in the left tiling. Such a move changes the position of the 3 tiles surrounding that vertex as represented in the next figure:

Figure 2: A move of L’OZ A prototype of the game is available at: http://labmag.di.fc.ul.pt/virtual/LOZ/. 2

The complete mathematical analysis of the game follows from results of [4]. Here, we focus the most relevant details of our implementation. In the next section we present the mathematical ideas and results used to encode the tilings, preventing distortions after several moves. Then, in section 3, we give the main details of the implementation of the game.

2 2.1

Mathematics behind the program Encoding the tilings

L’OZ tilings are edge-to-edge lozenge tilings of a centrally symmetric convex polygon, the n-zonogon Zn = Z(O, V ) spanned by a point O and the star , sin (i−1)π ), i = Vn of unit vectors Vn := (v1 , . . . , vn ) with vi = (cos (i−1)π n n i, . . . , n. ∗ ∗ ∗ The 2n vertices of Zn (seePFigure 3), O, O1 , . . . , OP n = O , O1 , . . . , On = i i ∗ ∗ O), are defined by Oi = O + i=1 vi and Oi = O − i=1 vi .

Figure 3: The star of vectors V5 and the corresponding zonogon Z = Z(O, V5 ) The tilings of our virtual L’OZ satisfy the following extra condition: (u) The edges of the tiles (lozenges) are translates of the edges of the zonogon.

3

Condition (u) is not mathematically necessary (see[4]) but it allows to give the player more choices on the number of edges of the zonogon (see section 3). From now on by L’OZ tiling we mean a L’OZ tiling satisfying condition (u). Note that condition (u) implies that every vertex of a L’OZ tiling must be of the form V = O + vi1 + . . . + vik , with I(V ) := {i1 , . . . , ik } ⊆ {1, . . . , n}. So every vertex of a L’OZ tiling may be identified with the n-sequence, s(V ), of 0’s and 1’s defined by: s(V ) = (1 , . . . , n ) ∈ {0, 1}n where i = 0 if i ∈ / I(V ) and i = 1 if i ∈ I(V ). In our algorithm, instead of using the real coordinates of the vectors to describe a tiling we use essentially the 0,1-sequences s(V ) of each vertex V of the tiling. This is the key to avoid distortions of the tilings appearing in the screen after a long sequence of moves. More precisely: 1) A L’OZ tiling L is encoded by an integer matrix M = M (L), each row of M corresponding to a vertex of the tiling. M is composed by two submatrices: M = [ M1 | M2 ]. For each vertex V the corresponding row of M1 is the 0, 1-vector s(V ) and the corresponding row of M2 is a sequence of integer numbers enconding (in a natural way) the degree and vertices adjacent to V in the tiling. 2) We translate directly in terms of M the effect of a L’OZ move. Once the player clicks on an inner vertex of degree 3 the program constructs the new matrix M 0 corresponding to the tiling obtained after reversing the three tiles surrounding that vertex. This construction involves dealing with integer numbers in a purely combinatorial way (no algebraic operations involved). Only once M 0 has been obtained the program translates into real coordinates the vertices, edges and lozenges of the new tiling that appears in the screen. So, at each move the all tiling is translated into real coordinates avoiding acumulation of errors after long sequences of moves. 4

It must be pointed out that the dimensions of the matrix M depend exclusively on two numbers: the number of vertices of the tiling, which is the number of rows of M and the maximum degree of a vertex in any tiling which determines the number of columns of M . The next proposition says that both numbers depend exclusively on n, the number of vectors spanning the zonogon.

Proposition. Let Z be an n-zonogon determined by a point O and the star of vectors V = (v1 , . . . , vn ). Consider a (any) L’OZ tiling L of Z. Then   n 1) l(L) := no of lozenges of L = 2   n e(L) := no of edges of L = 2 +n 2   n+1 o v(L) := n of vertices of L = 1 + 2 2) - Every vertex V of L as degree at most n.

In order to prove the proposition it is convenient to introduce the notion of zone of a L’OZ tiling - zones are a fundamental concept to study parallelogram tilings, the ”yellow brick roads” of L’OZ. Definition. Let L be a L’OZ tiling of an n-zonogon Zn . Let e be an edge of Zn with direction vi . The i-th zone Li of the tiling L is the longest sequence of parallelograms (P0 , . . . , Pm ) of L satisfying the following condition: for every i = 1, . . . , m the parallelogram Pi is adjacent to Pi−1 by an edge parallel to e. Note that every zone Li separates every pair of edges of the zonogon with direction vj (6= vi ). Therefore two distinct zones Li and Lj intersect in a unique lozenge.

5

Figure 4: Zone L1 and L4 and their intersection Proof of the Proposition 1) We count directly the lozenges and the edges of L or, equivalently, the bounded faces and edges of the plane graph G(L), the graph whose vertices and edges are the vertices and edges of the tiling. Every lozenge of L is contained in exactly two zones of L. On the other hand, every pair of zones intersects in exactly one lozenge implying that the number of lozenges in the tiling is the  number  of distinct pairs of zones. Since n Zn has n-zones we then have l(L) = . 2 The number of edges of L is the number of edges of the plane graph G(L). The faces of this graph are the lozenges, bounded by 4 edges, and the infinite face bounded by the 2n edges of the zonogon. Since every edge belongs to exactly two faces we have:   1 n e(L) = × (4l(L) + 2n) = 2 +n 2 2 Once we have the numbers of faces and edges of the tiling, we use Euler’s relation for plane graphs to obtain the number of vertices. The number of faces of the graph being l(L) + 1 we have v(L) = e(L) − l(L) + 1. The result follows. 2) Let V be a vertex of the tiling. By definition of zone of a L’OZ tiling V is the extremity of at most one edge of each zone of L. Since a L’OZ tiling of an n-zonogon has at most n zones, the degree of V is at most n. 6

2.2

A further mathematical remark.

As we have seen to every L’OZ tiling of an n-zonogon we can associate a family V of 0, 1-vectors of length n representing the vertices of the tiling the lines of the submatrix M1 of the encoding of the tiling described above. A challenging mathematical question is the following: Question. Characterize those subsets V ⊆ {0, 1}n that correspond to the vertices of a L’OZ tiling. Roughly, and geometrically, speaking this question asks for a characterization of those subsets of vertices of the n-dimensional cube [0, 1]n projecting (bijectively) into an affine plane of Rn as the vertices of a L’OZ tiling (see [4]). Complete answers to this question are known as axioms for maximal vectors of an affine uniform oriented matroid of rank 3 and follow from more general results of J. Lawrence [3] (for L’OZ tilings satisfying condition (u)) and of da Silva [5] for the general case.

3

Programming details

We have used the C++ programming language and the Open Graphics Library (OpenGL) to implement L’OZ. OpenGL [6] is a free multi-platform low level application program interface (API) for writing applications that produce 2D and 3D computer graphics. It was developed by Silicon Graphics Inc. in 1992 and is widely used in CAD (Computer Aided Design), virtual reality, scientific visualization, information visualization, flight simulation and in video games. OpenGL has become a widely accepted standard for developing graphics applications [1]. For the interface of the virtual L’OZ we used Microsoft Windows libraries (consequently this version of the game can not be played in a different operating system).

7

3.1

Interface with the player

Starting the game - screens and player choices When the player starts virtual L’OZ he is offered several choices. In the initial screen of the game he is asked to choose the number of vectors that generate the zonogon (possibilities vary between 4 and 9). Once the choice made the second screen appears. In the second screen the player is offered a certain number of tilings of a zonogon with the chosen number of edges. He must then choose one. This is the final configuration he must obtain. The initial configuration is always the same (a ”cyclic tiling”). Then the game starts. The main screen appears with the two different tilings of the same polygon: the starting ”cyclic tiling” (on the left) and the chosen final tiling (on the right), as in Figure 1. The player may now start solving the puzzle that means to transform the initial tiling into the final one with a sequence of L’OZ moves. The main screen of the game contains two sub-windows: the left and right sub-window. The left sub-window, where the player solves the puzzle, reacts to specific mouse events. An event is generated every time the player holds down a mouse button and releases it, that is, whenever he clicks a mouse button. The occurrences of a specific type of event can trigger a particular routine a callback function. In order to achieve this it is necessary to implement the callback functions in our code and to associate them to the respective type of event. Our program uses callback functions to treat mouse events. The right sub-window is static, that means, the player is not supposed to interact with it (can not change the final tiling), therefore no callback functions have been implemented to treat mouse events that occur in this sub-window. Playing the Game - clicks on mouse buttons in the left sub-window Every time the player clicks on the left button of the mouse the corresponding callback function checks if the click was performed over an inner 8

vertex of degree 3 (in a small defined circular area around it). If so, a legal move of the game was performed and the tiling changes; otherwise, nothing happens. If the player clicks on the right button of the mouse the corresponding callback function makes a small menu appear. This menu allows the user to exit the game, or to check if the final tiling was achieved and, if so, it provides the number of moves the player made in order to achieve the puzzle. Coloring OpenGL provides a set of primitive geometric objects to the programmer such as points, line segments and polygons. In our implementation of L’OZ, each parallelogram is displayed as an OpenGL polygon. Concerning the filling colors of the polygons, we have used the RGB (Red, Green, Blue) color model [2] and developed a scheme to avoid having adjacent lozenges with indistinguishable colors in the initial tiling. Each parallelogram maintains its color during the game.

References [1] E. Angel, Interactive Computer Graphics - A Top-Down Approach Using OpenGL, Addison-Wesley, 2006 [2] J. D. Foley, A. van Dam, S. Feiner, J. Hughes, R. Phillips,Introduction to Computer Graphics, Addison-Wesley, 1993 [3] J. Lawrence, Lopsided sets and orthant intersection by convex sets, Pacific J. of Math. 104(1983), 155-173. [4] I.P.F. da Silva, On fillings of 2n-gons with rhombi, Discrete Math. 111(1993), 137-144. [5] I.P.F. da Silva, Axioms for maximal vectors of an oriented matroid, Europ. J. of Combinatorics,16(1995),125-145. [6] OpenGL official website- http://www.opengl.org/

9