Sunday, January 13, 2013

Modern 10 PRINT ASCII-Art labyrinth generator

After reading a Slashdot post about the 10 PRINT one-liner maze generator, I spent many days thinking about how a simple random sequence of / and \ could make those labyrinths.
Anyone who tried to generate labyrinths from a program knows that it isn't an easy task, so I immediately wrote a program to test if that algorithm could be so good, and I got this output:
/\////\\//\/\//\\\\\/\//\\
\////\\\///\/\////\/\\/\/\
/\\/\\\///\/\/\///\/\/\/\\
/\/\\\\\//\/\\\\/\\\\//\\\
///\/\\\/\\///\/\/////////
/\//\/\//\\/\///\\\/\/\/\/
\////\\\/\/\\\\\/\/////\\/
/\//\/\/////\\//\/\\///\\\
\\\\///\\/\/\/\/\\//\\/\\\
///\\/\\//\\\\/\///\\/\\\\
Well, that wasn't exactly what I expected, and I quickly realized that there was a problem with the fonts, so I made some tests trying to change many parameters of the text in a word processor, without success. Modern "\" and "/" characters are not designed for such effect! And the separation of lines was also a problem.

Anyway, I was not satisfied yet, so I studied how to design a program to represent, generate and print such maze using horizontal and vertical characters, learning in the way a lot about this thing. Today I would like to publish my little program 10print.c for anyone interested. This was the result:
   |  ___  |   |   |   |  _______  |   |  ___  |  __
 | | |  ___|___|___|___|___  |  ___| | | |  ___|___ 
 |___| |   |   |   |  _______|___  | | | | |  ___  |
___  | | | | | | | |___  |  _______| | |___| |  ___|
   | |___|___| | |_______|___  |   | | |  ___| |  __
 | |___  |   | | |  ___  |  ___| | |___| |  ___|___ 
 | |  ___| | |___|_______|_______| |   | |___  |  __
___|_______| |  _______________  | | | |_______|___ 
   |   |   | |___  |  ___________| | |_______  |   |
 | |___| | |___  | | |   |   |   | | |   |   | | | |
 | |  ___| |   | |___| | |___| | | | |___|___| | |__
 | | |   | |___|_______| |  ___| | |___  |  ___| |  
 |___| | | |   |   |  ___|_______| |  ___| |  ___|__
_______|___| | |___| |   |   |   | | |  ___|___  |  
   |  ___  | | |  ___| | |___| | | | | |   |   | |__
___| |   | |___| |  ___|___  | | | | | |___|___|___ 
  ___|___|_______| |   |   | |___|___| |  ___  |  __
 |  ___  |  _______| | | | |_______  | |_______|___ 
 | |   | | |  _______| | |_______  | | |  __________
___| | |___| |   |   | |_______  | |___|___________ 
Much better! I haven't read the 10 PRINT book, but I enjoyed a lot doing this. Thank you for give me such an interesting problem!