Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 


Submitted by Jon Harrop, posted on March 22, 2005




Image Description, by Jon Harrop



Following a post on the comp.lang.functional newsgroup asking for a 2D maze generator written in a functional style, I wrote this little 131-line OCaml program to generate and render simple 2D mazes using OpenGL and also export the result as PostScript.

The program stores the set of visited grid cells as a mapping from (x, y) coordinates (of type "int * int") to booleans, implemented as a balanced binary tree by the OCaml library. The grid is then traversed recursively from the bottom left-hand cell (0, 0) by moving randomly to unvisited, on-board neighbours left, right, up or down.

The maze is rendered while it is generated, as OpenGL points and lines. The result is memoized in a display list for fast redisplay.

The complete source code, along with the compilation command, is available on-line here:

http://www.ffconsultancy.com/free/maze/

Cheers,
Jon.


[prev]
Image of the Day Gallery
www.flipcode.com

[next]

 
Message Center / Reader Comments: ( To Participate in the Discussion, Join the Community )
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Rhinoid

March 22, 2005, 09:18 AM

A maze typically has a beginning and an end...

now the beginning is clear to me... it is the bottom left corner (or is this a coincedence?)... but what is the goal of the labyrinth? ;^)

 
zOinks

March 22, 2005, 09:54 AM

Yea... where's the Cheese? Mouse needs to eat y'know

 
Jacco Bikker

March 22, 2005, 10:36 AM

I used to be quite interested in mazes a while back, and during that period I found this ultimate nerd maze:

http://www.clickmazes.com/dragon/ixdrag.htm

:)
About the IOTD: Is a maze generator relatively hard to do in a functional language? It's a while back since I last programmed in Miranda. :)

 
Michael Walter

March 22, 2005, 12:27 PM

No.

 
Joiey Seeley

March 22, 2005, 01:45 PM

Oh no, not Miranda! Now horrible memories are coming back!

 
ghavami

March 22, 2005, 06:39 PM

I tried that maze game there, Level 8 is almost unplayable due to the render target being too small, so it's "impossible" to see anything ^^

Now Ontopic: This looks like cool stuff, maze generation is a quite interesting issue when dealing with level generation e.t.c

 
This thread contains 6 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.