You are a medieval overlord tasked with designing a road network between three kingdoms placed on a \$9 \times 9\$ grid. A sample placement of kingdoms might look like this:
Non-commercial use of tileset by douteigami. Thanks!
The kingdoms make the following three demands:
- The road network must be connected: for any tile on the road network, you must be able to reach any other tile on the road network by just moving horizontally or vertically only along road tiles.
- The kingdoms must be connected: Every kingdom has at least one road tile immediately adjacent horizontally or vertically.
- The road network must be thin: No block of \$2\times2\$ squares can all be road tiles.
Both of the following road networks satisfy all three criteria:
The following setups fail to satisfy one of the three criteria:
Challenge
Take input of a \$9\times9\$ grid with three kingdoms in any format. This may be a multiline string with spaces and characters, a list of single-line strings, a list of zeros and ones, a matrix, or any other reasonable format for your language.
As output, add a road network to the input (indicated in any suitable way) that satisfies the above three criteria. Note that:
- The kingdoms will never be horizontally or vertically adjacent.
- There is no requirement that your road network be minimal in any sense, just that it follows the three rules.
- You may not place roads on top of kingdoms.
- A \$2\times2\$ block where three tiles are road and a single tile is a kingdom is OK; the third restriction only concerns four road tiles.
Test Cases
The test cases use .
for an empty space, k
for a kingdom and #
for a road, but you may take inputs in other formats/use any three distinct characters or integers as described in the previous section.
Input -> Possible output
......... .........
....k.... ....k....
......... ....#....
......... ....#....
.k....... -> .k####...
......... .....#...
.....k... .....k...
......... .........
......... .........
k.k...... k#k......
......... .#.......
k........ k#.......
......... .........
......... -> .........
......... .........
......... .........
......... .........
......... .........
.k....... .k.......
k........ k#.......
.k....... .k.......
......... .........
......... -> .........
......... .........
......... .........
......... .........
......... .........
......... .........
......... .........
k........ k#.......
......... .#.......
k........ -> k#.......
......... .#.......
k........ k#.......
......... .........
......... .........
........k ...#####k
....k.... ...#k....
......... ...#.....
......... ...#.....
......... -> ...#.....
......... ####.....
......... ...#.....
....k.... ...#k....
......... ...#.....
......... .........
......... .........
......... .........
......... .........
......... -> .........
......... .........
k........ k........
.k....... #k.......
..k...... ##k......
Here's the inputs as a list of list of lists, should you prefer that:
[[[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1,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