Skip to content
The Scroll Art Museum

Connected Pipes

Al Sweigart, 2024. Random squiggles that form a sort of connected pipework. There are some isolated sections but no dead ends.

Al Sweigart wanted to use box-drawing characters to form a random but connected shape, something like the old Pipe Dream game (originally called Pipe Mania when released in 1989).

Ensuring that there are no dead ends is a constraint satisfaction problem: Sweigart builds the pipes one row at a time from left to right. For each space in the row, he considers the adjacent spaces to the left and above. Only the current and previously printed rows need to be kept in memory. The space to the right and below the current space always has both possibilities of connection or no connection. When there are connections from the left and from above, the chosen box-drawing character needs to connect to the left and above, but random chance determines whether it also connects to the right and below.

There are two forms of this piece, configurable by the VERTICAL_STYLE_FACTOR variable. When set to 1.0, the program never sets the space to have a right-connecting pipe. This should mean that there are only straight vertical lines, because how could there be left-right horizontal connections if there's never a right connection?

Sweigart was surprised by this result. He then realized that when a space has only one dead-end connection from the left or above, it randomly includes connections down and right. He had added this behavior earlier for more variation, and by good fortune it produced the "elongated" vertical effect.

Sweigart also features the squarish form (where VERTICAL_STYLE_FACTOR is set to 0.0) for comparison. This value can be set anywhere within the 0.0 to 1.0 range to control the effect.

Python source code

Customize
Settings