12
The Game
Recently, much of my time has been taken up by an addicting game on my phone, called Logic Dots, which inspired me to write this challenge. It's easier to explain the rules if I show you the game display, so here is a screenshot of an unsolved, and solved puzzle:
Now here, there are three main things to notice.
- The game board (the 4x4 grid of squares in the center)
- The required shapes (the linked dots in the second bar from the top, under the score and menu, etc.), which are all lines, or
a
by 1 rectangles - The numbers over the rows and columns, which denotes how many dots need to be in the column, for a solution
The objective of the game is to fit the required shapes into the grid. You can rotate the shapes, but they cannot go in diagonally.
In the solution, notice that all shapes are created exactly once (because they are only in the required shapes once), and in this case they are all horizontal but they can also be vertical. The pink filled in squares denote squares not used.
Here is a bigger, and slightly more complicated grid:
Notice that in the unsolved puzzle, there are already a few squares filled i.n The greyed out squares signify blocked squares that you CANNOT place a dot on. The dots with tails tell you that a dot is in that spot, and it links to at least one more dot in the direction of the tail, but not in any other direction (including the opposite direction).
Notation
For the rest of this post, I will refer to the board using the following symbols:
- <, >, ^, v - Signifies a pre-placed dot with a tail extending in the direction of the point
- * - Signifies a dot. If given on an unsolved grid (input), it is an individual shape. If in output, then it is connected to the dots around it.
- # - Signifies a blocked grid square (where you cannot place a dot)
- -, | (hyphen and bar) - Signify a dot with a right and left tail, and a dot with an up and down tail respectively
- ** (space character) -** Signifies an empty space
Using these symbols, the latter example case (unsolved) can be represented as follows:
<
#
^ #
And the solution can be represented as:
*< * *
*
*
* *
* *#*
^ # *
Note that no two shapes can touch horizontally, vertically or diagonally, so the following case is not valid:
***
**
**
Challenge
Your challenge is to solve any logic dots puzzle, from 4x4 to 9x9 inclusive. You will receive four lines of input, then the game board. The lines will be as follows:
- 1st line, Shapes - The shapes to find, each given in the form
sizexquantity
(eg.3x2
for two shapes of length three) and separated by a space. Example line:3x1 2x1 1x1
- 2nd line, Columns - A space separated list of the required dot count for each column. Example line:
1 1 2 2
- 3rd line, Rows- A space separated list of the required dot count for each row. Example line:
3 0 3 0
- 4th line, Board size - A single integer, the board size,
B
The board is then given, and is B
lines of input representing the board using the notation mentioned above. For example, the complete input for the latter example case is as follows:
4x1 3x1 2x2 1x2
1 4 0 3 0 5
4 1 1 2 3 2
6
<
#
^ #
Your program will then output the solved board, in the same notation. The matching output for the above input is as follows:
** * *
*
*
* *
* *#*
* # *
Note that a game board can have multiple solutions. In this case, just output one valid solution. Also, your program must output a correct solution within 10 seconds on a reasonable desktop computer for a complicated 10x10 grid.
This is code golf, so least bytes wins.
Test Cases
Input 1
3x2 1x4
2 2 3 1 2
4 0 3 0 3
5
#
#
*
Output 1
*** *
***#
#
* * *
Input 2
3x1 1x6
2 0 4 0 3
3 1 2 1 2
5
*
#
Output 2
* * *
*
* *
* #
* *
Input 3
5x1 4x1 2x1 1x2
1 2 3 3 2 2
0 5 0 4 0 4
6
#
-
#
<
Output 3
#
*****
****
#
* ** *
Yes, that is correct @flawr – globby – 2015-01-29T20:49:34.640
@flawr
t no two shapes can touch horizontally, vertically or diagonally
(this should be at the beginning, not lost almost near the end, but anyway...) – edc65 – 2015-01-29T20:49:43.140@globby Wouldn't every empty space be replaced with #, I suppose the # is when you single tap an empty space in the game. When you finish a level it fills all empty cells. – Teun Pronk – 2015-02-02T13:13:21.850
@TeunPronk No. # are spaces which are predetermined that you cannot place a dot in the level, like the gray squares in the second example. – globby – 2015-02-02T15:21:48.103
@globby ah ok, clear now ^^ – Teun Pronk – 2015-02-02T15:33:19.873
Does it need to run in a reasonable amount of time? – KSFT – 2015-02-04T00:00:42.197
@KSFT within 10 seconds for complicated 9x9 grids on a reasonable computer – globby – 2015-02-04T00:02:06.293
2Better than offer a bounty, you should add more interesting test cases and fix the errors in your question. For instance, the last output before the current test cases still contains < and ^ – edc65 – 2015-02-04T21:32:30.657