CFUNITED Demo Derby Code

This post is more than 2 years old.

Yesterday at CFUNITED I presented some more (useless) code concerning mazes and ColdFusion. I've blogged on this a few times already, but I decided to play around with it a bit more. For the derby, I demonstrated code that generated mazes in a slightly different way than I've had before. I've shown outputting mazes with text. I've shown outputting mazes with graphics. But this version puts one more little spin on it - old school style:

What you are seeing here is a text based description of a maze stored in the session scope. This is done by first figuring out what directions are allowed based on your current position in the maze:

public function getExits(numeric x, numeric y) { var exits = ""; //handle west possible if(variables.mazedata.maze[arguments.y][arguments.x-1] == 0) exits = listAppend(exits, "west"); //handle east possible if(variables.mazedata.maze[arguments.y][arguments.x+1] == 0) exits = listAppend(exits, "east"); //handle north possible if(variables.mazedata.maze[arguments.y-1][arguments.x] == 0) exits = listAppend(exits, "north"); //handle south possible if(variables.mazedata.maze[arguments.y+1][arguments.x] == 0) exits = listAppend(exits, "south"); return exits; }

This then is used by a simple function to describe the current room. All rooms in the maze have the exact same look - it is only the exits that change:

function describePosition(numeric x, numeric y) { //better not be a wall or you are dead var exits = getExits(arguments.x,arguments.y); var s = "You are in a dark and dusty maze.<br/><br/>"; var i = "";
//Ok, I'm using pos with 0,0 in upper left				
if(listLen(exits) is 1) {
	s &= "There is one exit to the #exits#.";
} else {
	s &= "There are exits to the ";
	for(i=1; i &lt;= listLen(exits); i++) {
		s &= listGetAt(exits, i);
		if(i &lt; listLen(exits)-1) s&= ", ";
		else if (i == listLen(exits)-1) s&= " and ";
		//else if (listLen(exists) is 2 and i is 1) s
return s;


Movement is done by simply checking your current position against valid exits. Also note that I allow for shorthand versions of movements (e for east, etc):

public function move(string dir, numeric x, numeric y) { var pos = {x=arguments.x,y=arguments.y}; if(dir == "e") dir="east"; if(dir == "w") dir="west"; if(dir == "s") dir="south"; if(dir == "n") dir="north";
if(listFindNoCase(getExits(x,y), dir)) {
	if(dir == "east") pos.x++;
	if(dir == "south") pos.y++;
	if(dir == "west") pos.x--;
	if(dir == "north") pos.y--;
return pos;


Totally useless - and totally fun - and yes - I have inklings for other maze demos to try as well. I've attached the code (including the Grue version) but note that it is ColdFusion 9 only.

Download attached file.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Sid Wing posted on 8/15/2009 at 3:41 PM

Hey Ray! Here's a link to a bit of nostalgia for ya - :-)

Comment 2 by Raymond Camden posted on 8/15/2009 at 3:43 PM

Is this your site?

Comment 3 by Sid Wing posted on 8/15/2009 at 3:56 PM

Yes sir - and here's the blog article about it:


Comment 4 by Alexander Sante posted on 8/15/2009 at 7:30 PM

Reminds me of some old MUD games I used to play.

Comment 5 by Raymond Camden posted on 8/17/2009 at 5:38 AM

So Sid - maybe you know the answer to this. It is my impression that the client side game player thing (forgot the name) can save a game to the file system and restore it as well. So in theory, one could write a CFM wrapper and store their game data into a unique file.


Comment 6 by Sid Wing posted on 8/17/2009 at 5:14 PM

@Ray - One of the issues with the Java Applet it runs on is that fact that browser security does not allow for a "save game" - there is another z-engine out there that will store the save info as a URL variable that you can bookmark and I am looking at taking that - grabbing the URL variable with CF and storing it to a unique file so that I can then call those files from inside CF - feed it back as a URL variable and "load" a "saved" game .