Gunport Domino Puzzles

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]



Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only



Problem Description

A program to allow solution of "gunport" domino puzzles requiring that a board be covered with dominoes leaving the  maximum number of gunports; squares the size of half a domino. 

Background & Techniques

Here's another puzzle I found in my "1000 Play Thinks" puzzle book.  It belongs to a class of packing or covering type puzzles and has a broader background that I would have thought.  It was invented Bill Sands  in1971 and popularized by Martin Gardner in his Mathematical Games column for Scientific American (April 1974).  Donald Knuth described this class of puzzle which he called "Exact Cover Problems"  in a Dancing Links paper which unfortunately is only available in PostScript format at the link. One way to approach solving our puzzle programmatically would be to treat the gun ports as monominoes (1x1 squares) which converts the problem to an exact covering problem.. The best paper I found on this approach is this  Chond and Blsch paper .   I haven't worked on making this program solve the puzzles yet, but have implemented user play. 

There are 6 sample problems included ranging in size from 3x3 to 8x10 squares.  To play, simply click adjacent empty squares to add a domino and click an occupied square to remove the domino.  A congratulation message will reward the successful gunport count.   

Non-programmers are welcome to read on, but may want to jump to bottom of this page to download the executable program now.

Programmer's Notes:

Not much new in the code so far.  Clicks on the image are converted to column and row values which exist visually on the image and in a doubly dimensioned array (Board) of characters using "E' for empty, "L" and "R" for left and right halves of a domino, "U" and "D" for upper and lower halves of a domino, and 'X" for first click on an empty square.  The code is well documented  and should be easy to follow for those interested in more details.

 Addendum March 12, 2011:  Version 2 posted today adds a "Solver" button to search for solutions.  I implemented "Mod 4" of the LP (Linear Programming) solution algorithms defines in the Chond and Bosch paper referenced above.   Those guys used a modeling language to implement their search and translating that to the equation formats required  by the LPSolve module (introduced here in our LPDemo program) was an interesting challenge.  As a refresher, linear programming tries to maximize or minimize an "objective function" subject to linear equations representing constraints.  The input data is represented as a matrix of equation coefficients with a column for each variable and a row for each constraint equation.  The Chond/Bosch model used define three arrays (H, V, and M) of binary variables (values 0 or 1), each with as many entries as there are cells on the board.  H and V represent the left or upper cell of a Horizontal or Vertical domino, The M array represents "monominoes", the empty spaces surrounded by board edges or other H or V dominoes.  LPSolve doesn't handle arrays of variables that I could find, so I generate a variable for each cell (for an 8 x 10 board this means 3*80 or 240 variables!)  That also means a  constraint equation for each cell checking that the sum of the H, V, or M for cell equals 1.  The objective function for the setup is to maximize the sum of the M values.  Other constraints insure that the sum of all Monominoes equals the calculated maximum number and some symmetry constraints to improve performance by preventing checking configurations that represent rotation or mirroring of ones already checked.  Even with that, solving the 8x10 board required 13 hours of computer run time!  Lot's of room yet to work on improving the solution times. There is also a bug somewhere that causes the 8x8 board solution to overlap two vertical dominoes. 

I optionally allow users to save solutions in a list of optimal solutions found so far. With one exception, I've attached optimal solutions for all boards up to 10x9.  I invite anyone finding the optimal solution for 10x10 or the 11xN for larger N values, to send me the GunPortSolutions.stm file that will be built.  (Check "Allow solution updates" when making these runs!  Or, if you forget,  you can always make screen shot of the solution and send it.)

Addendum March 13, 2011:  It didn't take long to produce the next update.  Version 2.1 upgrades the LPSolve solver module from V5.1 to V5.5 which looks to be significant faster at finding solutions in the cases I've run so far.

Addendum March 18, 2011:  Oops.  V5.5 of LPSolve doesn't solve as many cases as V5.1 (it ran 20 hours without solving the 7x8 case which V5.1 solved in an hour).  Whether there is a problem with V5.5 or my implementation of it is unknown, but I reverted back to the 5.1 version and named it GunPorts512  Version 51.2.   I did speed up solving cases with either rows or column is a multiple of 3.  These cases have a trivial repeating pattern solutions which had been solved quickly only for the rows mod 3 = 0 case.  I now swap rows and columns for solving when columns mod 3 = 0 and swap back and exchange horizontal and vertical dominoes  for displaying the solution. 

March 22, 2011:  Help!  I'm working on this program and just can't stop!  I decided to reorder the variables fed to LPSolve, so the the Horizontal, Vertical, and Monomino binary variables for each cell are interlaced, (H1, V1, M1, H2, V2, M2...   HnVnMn   instead of H1, H2,...Hn,V1,V2,...Vn, M1, M2,... Mn).   This reduced solving time dramatically in some cases.  The 7x7 case is now solved in 3 seconds compared to 2 hours for the previous version!   However the10x10 board search ran for 49 hours before I stopped it with no solution found.  I am , however, proud to include  an optimal 10x10 solution found  manually by overlapping a 4x10 solution whose last row pattern happened to match the top row pattern of a 7x10 solution.  "More than one way to skin a cat" as we say here!   There are still invalid results produced occasionally (overlapping dominoes) which I need to debug .   

Running/Exploring the Program 

bulletDownload source
bulletDownload  executable

Suggestions for Further Explorations

Done 3/12/2011: Allow user defined board sizes
.Done 3/12/2001: Implement a solver.
Done 3/22/2011: Change order of Horizontal and Vertical variables in the LPSolve setup. Current arrangement is HHH...H, VVV...V with one h and one V variable for each cell in the problem.  Try HVHVHV...HV to force earlier consideration of Vertical dominoes.  


Original: January 21, 2011

Modified:  July 29, 2017

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.