Evolving Polyomino Puzzles Daniel Ashlock, Senior Member IEEE, Lauren Taylor Abstract—A polyomino puzzle is a collection of polyominos that can be joined to make a simple shape. The game Ten-Yen was one of the first of these. It has ten polyomino pieces that could be used to make a 6x6 square in a variety of ways. In this study we define representations and fitness functions for generating polyomino puzzles as well as developing a simple solver to compare the evolved puzzles. The solver can be used to approximate the number of solutions and hence the relative difficulty of the puzzles. Two types of fitness functions are compared, the second of which was developed to deal with scaling issues that arose with the first. A parameter study on the algorithm is performed and it is found that simply penalizing bad results is more effective than parameter tuning. This study concludes by discussing potential puzzle variants. like all of the pieces to be distinct polyominos, as in Ten-Yen, and that we would like the number of pieces to be relatively large (equivalently, we would like the pieces to individually be relatively small). I. I NTRODUCTION Polyomino puzzles are sets of polyominos that can be joined to make a simple shape. Figure 1 shows a polyomino puzzle called Ten-Yen that uses ten distinct polyominos in three colors. There are a large number of ways to assemble the pieces and it is possible to declare secondary challenges such as making all the pieces that share a color form a contiguous region, or surrounding one color with another. An example of such a solution appears in Figure 2. If a puzzle of this sort has one solution then it typically has many, but the number of solutions varies substantially from puzzle to puzzle. Fig. 1. The Ten-Yen game, patented by Multiple Products Corporation in 1950. In this study we develop a representation and compare several fitness functions for creating polyomino puzzles. Our fitness criteria are based on the assumption that we would Daniel Ashlock and Lauren Taylor are with the Department of Mathematics and Statistics at the University of Guelph,dashlock@uoguelph, [email protected] The authors thank the Canadian Natural Science and Engineering Research Council of Canada (NSERC) for supporting this work. Fig. 2. A solution to Ten-Yen with contiguous regions for each color. The on-line encyclopedia of integer sequences (OEIS) (https://oeis.org/) is a catalogue that lists sequences of integers that are interesting, together with the reason or reasons they are interesting. The sequence A000105 in the OEIS counts the number of polyominos with n squares. The prefix of this sequence is 1, 1, 1, 2, 5, 12, 35, 108, 369, 1285, 4655, . . . telling us there is one polyomino with no squares, one with one, one with two, through 4655 distinct polyominos with ten squares. The relatively small number of small polyominos constrains the design of polyomino puzzles. In this study we develop a simple string representation for evolving polyomino puzzles. The challenging part of finding a system for evolving these puzzles is the fitness function. The representation specifies a set of polyominos that cover a square, but we must avoid having repeated polyominos and also trivial solutions. The initial design for the fitness function forbids (by awarding minimal fitness) a polyomino with one piece - a design that is clearly not a challenging puzzle. As we will see, it is not too difficult to write fitness functions that reward piece diversity, but neither is it trivial. Both types of fitness functions designed in this study had large, low-quality local optima. The remainder of this study is structured as follows. Section II looks at other material on polyomino puzzles and puzzle solving with evolutionary algorithms. In Section III we explain the representation for evolving polyomino puzzles and a shotgun solver is also outlined for sampling solutions. Section IV gives the experimental design for testing the puzzle evolver. Section V presents and discusses the results, including the comparison of evolved puzzles, while Section VI draws conclusions and outlines next steps. II. P OLYOMINO P UZZLE AND E VOLUTIONARY P UZZLE C ONSTRUCTION An excellent introduction to the combinatorics of polyominoes as well as a large number of puzzles and problems can be found in [3]. A premier source of polyomino based (and other) puzzles is Kadon games 1 , including a modern edition of the game Ten-Yen. Apps for puzzles like the ones evolved in this study are also available on Google Play 2 . A general survey on automatic content generation, which includes the generation of puzzles, appears in [9]. Evolutionary algorithms have been used to generate, solve, and rate the difficulty of Sudoku puzzles [6]. A large number of publication use evolution on Sudoku, e.g. [5], but the primary goal is solving rather than generating the puzzles. Mazes are another type of puzzle generated using evolution. Multiple different sorts of mazes appear in [1]. An interesting application that uses a reaction-diffusion representation is used to evolve mazes from images in [10]. In general it is far more common for evolution to be used to solve puzzles than generate them. so that the actual chromosome for the configuration, sans color, for the arrangement shown in Figure 1 is: 302110212302100230221002020210110110 To complete the description of the representation, the variation operators used are two point crossover and multi-point mutation. The mutation operator chooses between 1 and M N M positions in the chromosome and replaces them with new values. The parameter M N M specifies the maximum number of mutations. A. Fitness Functions Two fitness functions were used. The first one works well for 6 × 6 puzzles but produces problematic results when the puzzle size is increased to 10 × 10. The second function was implemented to address the problems that arose for larger final shapes. The software used to build puzzles has an equality test for polyominos that works in spite of their flip or rotation status. Figure 4 shows the eight forms of one of the TenYen pieces. A piece can have one, two, four, or eight forms, depending on which rotations and flips in the dihedral group D4 preserve or modify the squares the piece is occupying [4]. III. R EPRESENTATION AND F ITNESS Polyomino puzzles are represented by decomposing the final shape, e.g. a 6x6 square, into polyominos with local connectivity specifiers. This is done by taking the individual squares of the shape and determining which other squares they are connected to. A loci with a value of zero generates no connections. A one connects a square to the one to its right, a two connects a square to the one below it, and a three connects to the squares both to the right and below. This permits any set of possible connections to be made. An important semantic issue, given that some squares have no square to their right or below them, is that a connection that goes off the edge of the final shape is ignored. An example of a gene that induces the polyominos in Figure 1 is given in Figure 3. The reader is invited to check its correctness. 3 2 1 2 0 1 0 1 0 2 2 1 2 2 0 1 0 0 1 3 2 0 2 1 1 0 3 0 1 1 0 2 0 2 0 0 Fig. 3. This gene in the connectivity representation yields the polyominos in Figure 1, in the arrangement they appear in in that figure. The chromosome structure used in evolution is unpeeled from the template of the final shape by rows 1 http://www.gamepuzzles.com/ 2 https://play.google.com/store/apps?hl=en Fig. 4. Shown are the eight possible orientations of the L-shaped Ten-Yen piece. Once it is possible to test for equality of polyominos, a chromosome C is parsed to determine the connections it specifies and then the connected regions, in the form of polyominos, are found. If the number of times the ith polyomino occurs is rk , the size of the ith polyomino is si , and 1 all polyominos are distinct U= (1) 0 otherwise then the two fitness function are 1 f1 (C) = U + P 2 si (2) and f2 (C) = U + P s2i 1 P + (rk − 1)2 (3) Note that the k index is over the polyominos for which at least one instance occurs, while the index i is over all polyominos no matter if they are distinct or not. We term the first fitness function the simple fitness function and the second the diversity penalized fitness function. Fig. 5. An example of a 10x10 puzzle with excellent piece size and very bad piece diversity. Note the large number of single-square polyominos. Fig. 6. An example of a 10x10 puzzle with unique pieces but an insufficient number of pieces. The value U is simply the reward for having all polyominos distinct from one another. The fractional terms require more explanation. The term X s2i At the other extreme, the solution shown in Figure 6 gains the uniqueness penalty, placing its fitness in the range (1,2) but has a polyomino with 99 squares, meaning that it has the lowest possible fitness in the range (1,2), given that singlepiece solutions are not permitted. Several approaches were used to discourage this behavior and the simplest - detecting this local optima and forbidding it by awarding it a fitness of zero - turned out to be the best. The other solutions for this issue appear in the experimental design and results sections. is the sum of the squared sizes of all polyominos that appear. Squaring the terms causes large polyominos to contribute disproportionately to the total; since the term is in the denominator of both fitness functions, this means that a puzzle with smaller pieces will have a smaller denominator and hence a higher fitness. The term X (rk − 1)2 is zero if all the polyominos are distinct. Repeated polyominos generate a positive values and, because the term is in the denominator, it functions as a fitness penalty. The U term and the contribution of the squared rk − 1 terms are somewhat redundant, but serve different functions. The U term makes a puzzle with unique pieces better than one without them. The rk − 1-based terms create a fitness gradient that incrementally rewards eliminating duplication. If individual polyominos are not unique, the fitness values are in the range (0,1), otherwise they are in the range (1,2). Both fitness functions consider having unique polyominos to be more desirable than keeping the size of individual polyominos small. The motivation for the second fitness function is exemplified by the puzzle in Figure 5. This solution fails to win the reward U for unique polyominos. If no member of the population gains U then the most fit puzzle is one that only uses single squares, something the solution in Figure 5 is approximating fairly well. The penalty term involving rk − 1 in the second fitness function acts to discourage this type of solution. B. Exhaustive Enumeration and Sampling of Solutions Algorithm 1 is an exhaustive enumerator. If we have a covering of a simple shape by polyominos (a solution) then, in any fixed scanning order of the individual squares, there is an order of the current orientations of the polyominos in the solution so that, when place in the first position where they fit, they reconstruct that solution. Thus, if we exhaust all orders of presentations of polyominos in all possible orientations, we will enumerate all possible solutions. Algorithm 1: Input: A set P = {p1 , p2 , . . . , pn } of polyominos and a shape S to cover. Output: The number of possible ways to cover the shape. Details: For all possible orders of polyominos Using the current order Compute number of possible orientations for each Initialize counter to zero Label:Rectop If(no polyominos) increment counter return Else For all polyominos p For each orientation pO Scanning by rows, if pO fits put pO in the first place it fits V. R ESULTS AND D ISCUSSION Recursively call at Rectop with remaining polyominos For purposes of discussing results, a failure is a puzzle that Remove pO does not have unique pieces, a trivial solution is a puzzle with End Scan two pieces, and a good solution is one that has many unique End For End For pieces. The case of a puzzle having a small number of unique End For pieces does not arise. Algorithm 1 is O(n!) where n is the number of polyominos since the number of orientations is at most 8 it does not affect the big-oh order of the algorithm. Even for the 6x6 puzzles this algorithm had an unacceptable runtime so it was modified to randomly sample polyomino orders and report the number of solutions relative to a sample size. In [2], the authors show that polyomino puzzles of the sort generated in this study are NP-hard; this means that while enumeration or sampling may work well for the relatively small puzzles generated here, more sophisticated solvers may be required for larger puzzles. A. Results for the 6x6 puzzles. IV. E XPERIMENTAL D ESIGN The baseline evolutionary algorithm used to create puzzles in this study is steady state [8] operating on a population of 1000 genes with M N M = 3 using single tournament selection with tournament size 7 as the model of evolution. This model of evolution selects a set or tournament of population members, copies the two most fit over the two least fit, and then applies the crossover and mutation operators to the copies. The size of the tournament controls the degree of selection pressure, with smaller tournaments yielding lower selection pressure. The baseline algorithm is run for 100,000 instances of tournament selection, called mating events. A parameter study, varying population size, the M N M parameter, and the choice of fitness function is performed. For each set of parameters and fitness function tested, 30 independent runs of the algorithm are performed. An example of puzzles resulting for the experiment with default parameters appears in Figure 7. The experiments performed were as follows; experimental parameters not explicitly listed are set to default values. Four experiments using the simple fitness function on the 6x6 version of the problem with M N M set to one of 1, 3, 5, or 7. Next a run for the 10x10 problem was performed, first using the default parameters and simple fitness. The results of this experiment were poor, motivating the development of the diversity penalized fitness function. The experiment was re-run using the new fitness function, and a large number of 2-piece solutions were located like the one shown in Figure 6. A parameter study was then run using 1,000,000 mating events and population sizes of 3000, 5000, 7000, and 9000 with diversity penalized fitness for the 10x10 problem. Finally experiments were run for the 10x10 problem for each fitness function, but awarding solutions with two pieces a fitness of zero - in effect prohibiting solutions of the type given in Figure 6. Fig. 8. Results of the mutation parameter study for the 6x6 puzzle problem using the first fitness function. All runs located a global optima - this figure shows the distribution of the fraction of evolutionary time required to do so. Four sets of runs were performed for the 6x6 puzzles with different mutation rates. In all four experiments, every run found a good puzzle that was globally optimal. This meant that the parameter study on mutation, the results of which appear in Figure 8, is somewhat moot. Rather than comparing these runs on their fitness, we compared them on their time to locate a global optima. The result is simple - a smaller mutation rate located global optima sooner, but, since all the mutation rates tested yielded 30 global optima, this is a soft parameter choice. We now need to explain why the optima located were global. In the introduction the number of distinct polyominos of small sizes were given. Every single optima located in these experiments had polyominos of size 1, 2, 3, 4, 4, 4, 4, 4, 5, 5. Fitness rewards smallness and so this configuration uses all five polyominos of size 4 but skips one with size three. The constraint that there must be pieces with a total area of 36 means that, if we want to use both polyominos of size three we get a piece size spectrum of 1, 2, 3, 3, 4, 4, 4, 5, 5, 5. Exhaustive enumeration (calculations not shown) shows that all other configurations are worse, so the optima found have the best possible fitness for the 6x6 case. This means that the algorithm presented in this study is more than equal to the 6x6 problem. An experiment was performed where any global optima was awarded a fitness Fig. 7. The puzzles located using default algorithm parameters for the 6x6 puzzle problem with the simple fitness function. of zero and the algorithm proceeded to locate 30 different solutions exhibiting the second assortment of piece sizes given above. This result motivated the “simply do not allow two piece solutions” experiments for the 10x10 problem, which had a problem with locating trivial 2-piece solutions. The fact that the number of distinct polyominos is known means we can also compute the number of global optima for the 6x6 problem. There is a single polyomino of sizes 1 and 2, two of size 3, five of size 4, and twelve of size 5. This tells us that the number of global solutions is: 2 5 12 1×1× × × = 132 1 5 2 For the next most fit set of sizes this total is: 5 12 2 × × = 2200 1×1× 3 3 2 which suggests that the algorithm was doing well to always locate the rarer global optima. The motivating puzzle Ten-Yen is one of the 2200 secondary optima. B. Relative Difficulty of 6x6 Puzzles Table I shows the three replicates of the solution-sampler described in Section III-B for each of the puzzles shown in Figure 7. Three replicates were run for each puzzle to get an idea of the sampler’s variability. The variation between replicates is much smaller than the variation between puzzles, which certifies that the sampler is capturing the relative number of solutions to the puzzle well. The evolutionary algorithm, when evolving a puzzle, certified that it found a puzzle by locating a gene that specified one solution to the puzzle. The sampler picks 1000 different orders of the pieces and then, for each order, exhaustively finds all solutions which place the pieces in that order, using all their potential orientations. The variability of this sampler is not simple to compute due to the confounding effect of the polyomino orientations, so three replicates were used. The results in Table I demonstrate that there is considerable variation in the number of solutions each puzzle has. It is intuitive that a puzzle with more solutions is one that an inexperienced player would have an easier time solving, so we used the number of solutions as a surrogate for the difficulty of the puzzles. Thus, puzzle difficulty varies considerably. A similar study was not performed for the 10x10 puzzles because its computational cost was quite high. TABLE I S HOWN ARE THE NUMBER OF SOLUTIONS FOUND IN 1000 SAMPLED ORDERS ON 6 X 6 PUZZLES USING ALL ORIENTATIONS OF EACH POLYOMINO - ONE ORDER MAY FIND MULTIPLE SOLUTIONS BASED ON POLYOMINO ORIENTATION . T HE PUZZLES BEING SAMPLED ARE THOSE SHOWN IN F IGURE 7. F OR EACH PUZZLE , THREE REPLICATES OF THE STOCHASTIC SAMPLER WERE PERFORMED . Puzzle 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Rep 1 14930 7882 16162 13408 4400 13482 5104 7841 9533 5729 5368 15226 8390 13931 9538 7726 27963 29083 8541 8180 3124 10579 15549 21262 7986 13377 22968 10782 25334 15292 Rep 2 15204 8231 16260 14087 3708 13576 5367 8061 9397 5255 4740 14026 7939 14715 9324 8753 27279 29240 7922 7764 3113 11413 15569 22237 8224 15268 20036 10738 27793 15154 Rep 3 14431 7773 14973 13877 3577 14321 5833 8479 9703 5287 5564 14794 8293 15202 9803 7841 28574 27555 7677 7726 3570 11685 15354 20246 7947 14485 21426 9899 27734 14974 C. Results for the 10x10 puzzles Since the problem of locating 6x6 puzzles proved relatively easy, 10x10 was chosen as a problem case sufficiently difficult for meaningful experimentation. The results of experiments on the 10x10 version of the problem are given in Table II. These experiments attempted to address two problems, the location of puzzles that failed to have all their pieces distinct and the problem of finding trivial two-piece puzzles. The simple fitness function located no good (non-trivial) puzzles and failed at achieving piece diversity five times in thirty. Two techniques were tried to address this problem, using the diversity penalized fitness function and simply returning zero fitness on trivial puzzles which Table II lists as trivial forbidden. Changing the fitness function has a mixed outcome, yielding 14 more good puzzles but also more than tripling the number of puzzles that failed to achieve piece diversity. Increasing the population size solved this problem - which is a low cost option since the number of mating events was held constant. Superior to increased population size was the modification of the fitness function to harshly penalize trivial puzzles. This caused the simple fitness function to achieve much better performance - something that is a bit puzzling as the number of non-diverse puzzles dropped to 1 from 5 - but this may have been simple luck. Implementing Div. Pen fitness in conjunction with forbidding trivial puzzles yielded 30 good puzzles, as did using populations of 7000 and 9000 puzzles, so two different solutions to the performance problems of the original algorithm both worked well. TABLE II R ESULTS OF THE POPULATION SIZE STUDY AND STRICT PENALTY RUNS FOR THE 10 X 10 PROBLEM . Fitness Function Simple Div. Pen. Div. Pen. Div. Pen. Div. Pen. Div. Pen. Simple Div. Pen. Population Size 1000 1000 3000 5000 7000 9000 1000 1000 Fail 5 16 1 2 0 0 1 0 Trivial 25 0 0 0 0 0 0 0 Good 0 14 29 28 30 30 29 30 Trivial Forbidden no no no no no no yes yes If we look more closely at the impact of changing the population size on the types of puzzles that are located, we see that in at least one sense the smaller populations, excepting the smallest, are better. Figure 9 shows the distributions of final fitness values for the five experiments that changed population size. The smallest population failed to find diverse puzzles far too often, an effect that dominates the display in the left panel of Figure 9. The zoom onto the other four runs in the right panel shows that, while increasing population size decreased the number of diversity-failures, it also decreased final fitness. The good solutions in the runs with smaller population were managing to have diverse sets of smaller pieces - one of the goals embedded in the fitness function. Fig. 9. Shown are box-plots of the distribution of best fitness values for the population-size parameter study on the 10x10 problem using Div. Pen. fitness. The top panel shows all five sets of runs while the bottom panel shows the part of the upper range for the last four sets of runs chosen to make the variation in fitness comparable. VI. C ONCLUSIONS AND N EXT S TEPS This study demonstrated a representation for evolving polyomino puzzles that had no problem creating globally optimal 6x6 puzzles, but required some tuning and a better fitness function to create acceptable 10x10 puzzles. A sampling algorithm demonstrated that the different evolved 6x6 puzzles had substantial variation in their hardness. In this study each sampling of the number of solutions of a given puzzle, for a fixed number of greedy solution attempts, was replicated three times because the sampling strategy was complex enough to make it unclear how uniform the sampling was. This sampling Fig. 10. The 10x10 puzzles located with the Dev. Pen. fitness and with 2-piece solutions forbidden. study demonstrated acceptable replicability of the numbers of solutions found across the three replicates to give confidence that the relative difficulty of the puzzles was being captured. A goal for future research is to find a more sophisticated strategy for enumerating the solutions of these puzzles. A good candidate is Monte-Carlo tree search (MCTS) which has been used [6] as a solver for a game called Blokus Duo which is not dissimilar to the polyomino puzzles proposed in this study. Multiple replicates of the solution sampler showed that its output is reliable as a measure of relative difficulty, but complete enumeration would yield more accurate results. Approaches like MCTS would permit more quantified measures. Permitting an MCTS solver a fixed amount of time and counting the number of solutions located would be an obvious approach. A. Solving or Designing? In the course of performing background research for this study, the authors found many papers on using evolution to solve puzzles for each paper on using evolution to design puzzles. On reflection, the authors feel this is an odd distribution of effort. There is a great deal of AI research that has yielded subtle, powerful algorithms for tree search that can be used, among other things, to solve puzzles. Designing puzzles, however, is a much more difficult and more poorly specified task. This means that it is likely to be more appropriate as a target for evolutionary computation. Perhaps researchers are more likely to choose easier problems, but we exhort our colleagues to put more effort into learning how to use evolution to design puzzles. We also apologize to any evolutionary puzzle designers whose work we missed. B. Varying Connector Probability A mathematical analysis of the increase in difficulty of locating polyomino puzzles of larger sizes suggests that part of the problem is that larger objects have more chances to be connected or to form large, connected sub-objects. This phenomenon is an instance of the Kolmogorov zero-one law [7]. This, in turn, suggests a way to modify the representation to achieve better performance. The current representation uses four equally likely values at each loci which form no connections, a connection to the right, downward, or both right and downward. Modifications to the code that generates the initial population and performs mutation to use non-uniform probabilities, enhancing the probability of the “no connection” value for example, could be used to tune the expected connectivity of population members, potentially adjusting for higher connectivity in larger objects. C. Secondary Puzzles In the original Ten-Yen puzzle, the directions not only gave the goal of assembling the pieces into a 6x6 square but also gave goals such as “make the colored regions contiguous” or “make the border of the puzzle black”. Secondary goals of this sort make a puzzle into a collection of puzzles and hence more interesting to potential users. The only goal of coloring the pieces of the puzzles located in this study was to provide relatively high-contrast drawings. It would not be difficult to incorporate secondary puzzle goals into the fitness function for locating polyomino puzzles. This might require that the representation be made more complex so that it contains information about what color each piece is. The best way to implement such a system is another nature next step for this research. D. Other Shapes and Objectives Modifying the code used in this study to make polyomino puzzles for shapes other than squares is an almost trivial modification, so long as the size of these objects is not too large. There is another potentially more interesting modification, which is to evolve sets of polyominos that can fill multiple shapes. In the simplest case, the pieces for a 6x6 puzzle could also be asked to fill a 4x9 rectangle. The current evolutionary setup is not one that could be modified easily to this task. For this, a puzzle solver such as MCTS, would be needed as the core of the fitness evaluation. The representation would specify a collection of distinct polyominos and fitness would be based on the ability of the solver to fill the target shapes with those polyominos. A natural choice would be the geometric mean of the number of solutions found for the different targets, or multi-criteria optimization could be used. R EFERENCES [1] D. Ashlock. Automatic generation of game elements via evolution. In Proceedings of the 2010 IEEE Conference on Computational Intelligence in Games, pages 289–296, 2010. [2] E. D. Demaine and M. L. Demaine. Jigsaw puzzles, edge matching, and polyomino packing: Connections and complexity. Graphs and Combinatorics, 23(1):195–208, 2007. [3] Solomon W. Golomb. Polyominoes, puzzles, patterns, problems, and packing. Princeton University Press, 1996. [4] T. W. Hungerford. Albegra. Springer-Verlag, New York, 1974. [5] A. Moraglio, J. Togelius, and S. Lucas. Product geometric crossover for the sudoku puzzle. In Evolutionary Computation, 2006. CEC 2006. IEEE Congress on, pages 470–476, 2006. [6] K. Shibahara and Y. Kotani. Combining final score with winning percentage by sigmoid function in monte-carlo simulations. In Computational Intelligence and Games, 2008. CIG ’08. IEEE Symposium On, pages 183–190, Dec 2008. [7] D. Stroock. Probability theory: An analytic view (revised ed.). Cambridge University Press, Cambride, MA, 1999. [8] Gilbert Syswerda. A study of reproduction in generational and steady state genetic algorithms. In Foundations of Genetic Algorithms, pages 94–101. Morgan Kaufmann, 1991. [9] J. Togelius, G.N. Yannakakis, K.O. Stanley, and C. Browne. Searchbased procedural content generation: A taxonomy and survey. Computational Intelligence and AI in Games, IEEE Transactions on, 3(3):172– 186, Sept 2011. [10] L. Wan, X Liu, T. Wong, and C. Leung. Evolving mazes from images. IEEE Transactions on Visualization and Computer Graphics, 12(2), 2010.
© Copyright 2026 Paperzz