Modern board games are a rich source of interesting and new challenges for combinatorial problems. The game Nmbr9 is a solitaire style puzzle game using polyominoes. The rules of the game are simple to explain, but modelling the game effectively using constraint programming is hard.
This abstract presents the game, contributes new generalized variants of the game suitable for benchmarking and testing, and describes a model for the presented variants. The question of the top possible score in the standard game is an open challenge.
Nmbr9 [Wichmanm2017] is a solitaire puzzle game using polyominoes that can be played by multiple people at the same time. The goal of the game is to build layers of the polyominoes in Figure 1 according to a pre-defined but unknown shuffle, and to place polyominoes representing larger numbers higher up to score points.
The game consists of polyominoes representing the numbers 0 to 9, two copies per number for each player. A common deck of 20 cards with the polyominoes are shuffled.
When a card is drawn, each player takes the corresponding part and places it in their own area. Placements are done in levels, where the first level (level ) is directly on the table, and level is on top of level .
Placement must always be done fully supported (level is always fully supported, level is supported by previously placed parts in level ). Each level must be fully 4-connected (i.e., not diagonally) after placement. The final requirement on placements is that when placing a part on top of other parts, it must be on top of at least two different parts. For example, if a 9-part is in level , then an 8-part can not be placed in level resting solely on the 9-part.
When all cards have been drawn, the score is computed as the the sum of the value for parts times their level minus one. For example, an 8-part on level 3 is worth 16, while it is worth 0 on level 1.
We define variants of Nmbr9 to get a larger sampling of problems to solve, from small trivial problems to larger intractable problems. Let be the scheme, where
Whether the draft is unknown, free to choose, or known. The first corresponds to a quantified problem, where the draft is -quantified. The second models the question of the max possible score, while the last models the max possible score given a specific known shuffle.
The maximum value to use, from 0-9.
The number of available copies of each polyomino.
The number of cards in the deck to use, must hold.
With this taxonomy of variants, the standard game is , where all available parts are used. Reducing , , or are all effective ways to make the model smaller. variants are interesting for answering the question of the top-score possible. variants are interesting computationally because they represent a much simpler but still hard problem, and are also interesting recreationally given a finished game, where participants wonder how they compare to the best possible result for that particular shuffle.
At Board Game Geek, a forum thread on solving the standard instance has a top score of 229 points, using a total of 7 layers [Kuenzler2018].
3 Constraint programming model
In this section, a constraint programming model is described for Nmbr9 in the and variants; a quantified model for the variant could be built as an extension on top of this. The model is based on the models in [Lagerkvist and Pesant2008, Lagerkvist2019], where regular constraints are used for placement of polyominoes in grids.
Nmbr9 is played on a conceptually infinite grid, with as many layers as needed available. The model used here requires a fixed grid. In practice, placements very seldom surpass 20 squares wide, and more than 7 layers is unlikely. The width/height size and the number of layers are parameters for the model. A core problem is keeping levels connected. This is accomplished using the technique of defining an area around parts, here as a new value. Also, parts may not be placed, which is controlled using reification of the regular expression. As an example, the regular expression for part 0 (called ) in its two rotations, where the value 0 is an empty square, 1 is a square occupied by the part, and 2 is an area surrounding the part becomes (including initial control variable for reified placement)
Let () be the set of parts, and the value of each part. Variables represent the deck of polyominoes, and the order of the polyominoes as they occur in the deck, with values above representing not used. The matrix is the grid for level for all parts on that level (of size , domain , border is 0), and the grid for a part on level (of similar size, domain ). Variables and are Boolean matrices representing when is 1 and 2 respectively. Boolean variables represent being placed on level , integer variable the level of (if any, 0 if not), and a Boolean variable representing that is placed with the inverse. The following defines the constraints of the model, where is implicitly assumed to range over with , over , over , and over . Operators and are used for point-wise logical operations. The notation is used to indicate true iff any element in the matrix M is true.
Constraint 1 checks that the deck is a shuffle of parts. Constraint 2 is the core placement constraints, with regular constraints in total. Constraints 3 to 8 channel information between variables. Constraints 9 to 11 implement the requirements for connectedness and being placed supported and on top of at least two different parts. When , then constraint 1 is equivalent to an alldifferent, and in constraint 3 there are no extra variables representing fake deck placement for non-used parts.
Finally, constraint 12 sums up the score of the solution, where is 0 for non-used parts ( and ), and also for parts in the first layer ( and ).
Choices are made on the deck, then the levels of parts, then the placements. A static variable order is used spiralling out from the centre to keep placement centered in the grid for as long as possible. Extra implied constraints that the first card is on the first level, and that the area for each level is at most the area for the level above are added. The latter improves performance significantly.
It is intractable to find a max score for the standard game approaching the score found manually using this model and search strategy; the model has more than 2.5 million propagators, and setting up the root node takes 5 seconds. A small problem like with 3 levels and grid size 8 takes more than 30 seconds and 80k failures to solve.
As seen, modelling Nmbr9 is surprisingly complex, mainly due to the connectedness and support requirements. This leads to a large model with not much propagation. Finding the maximum score for the standard game is a computationally hard open challenge.
Future work include: exploring how large problems can be solved with the current model; investigating better models for stronger propagation; and finding effective heuristics for the search. For search heuristics, thepropagation guided global regret in [Lagerkvist2019] might be very interesting.
Thanks to Magnus Gedda, Magnus Rattfeldt, and Martin Butler for interesting and informative discussions on games and search methods.
- [Gecode team2019] Gecode team. 2019. Gecode, the generic constraint development environment. http://www.gecode.org/.
- [Kuenzler2018] Kuenzler, P. 2018. Board Game Geek – Nmbr9 Forums, What is the highest possible score? https://boardgamegeek.com/article/30607221#30607221, [Accessed 2019-08-27].
- [Lagerkvist and Pesant2008] Lagerkvist, M. Z., and Pesant, G. 2008. Modeling irregular shape placement problems with regular constraints. In First Workshop on Bin Packing and Placement Constraints BPPC’08.
- [Lagerkvist2019] Lagerkvist, M. Z. 2019. State representation and polyomino placement for the game patchwork. In The 18th workshop on Constraint Modelling and Reformulation.
- [Wichmanm2017] Wichmanm, P. 2017. NMBR 9.