Connect! in JS

Published January 10, 2008
Advertisement
Game: http://members.gamedev.net/TANSTAAFL/connect/connect.html

Source In RAR File: http://members.gamedev.net/TANSTAAFL/connect/connect.rar

Tested in IE7 and Fox2 only. Its a little slow to load on both(it's generating a 8x8 maze in &#106avascript).<br><br>Enjoy.<div> </div>
Previous Entry Connect!
0 likes 1 comments

Comments

johnhattan
Works fine here. The strategy started out fairly automatic, ala ConFusebox, with the pieces that have no choice as to how to orient themselves. After that I just rather speculated as to how to complete the puzzle and managed to do it. I suspect there are likely several solutions to each maze.

Still, a nice game. Good find.

As for speed, here's Eller's Maze Algorithm in ActionScript. It's fast.


createMaze = function(width, height)
{	// generate a maze using eller's algorithm. Does not generate left or top wall. Assume it's there.
	var arrLeft = new Array();
	var arrRight = new Array();
	var retMaze = new Array();
	var wallBelow = 0x01, wallRight = 0x02;

	for(var a=[1]; a<=width; a++)
	{
		arrLeft[a] = a;
		arrRight[a] = a;
	}

	for(var a=[1]; a<height; a++)
	{
		for(var b=[1]; b<=width; b++)
		{
			if(Math.ceil(randVal()*[5])>[2] && b!=width && arrRight[b] != b+[1])
			{
		        arrLeft[arrRight[b]] = arrLeft[b+[1]];
		        arrRight[arrLeft[b+[1]]] = arrRight[b];
		        arrRight[b] = b+[1];
		        arrLeft[b+[1]] = b;
		        cellVal = [0];
			}
			else
				cellVal = wallRight;

			if(Math.ceil(randVal()*[5])>[2] && arrRight[b] != b)
			{
				arrLeft[arrRight[b]] = arrLeft[b];
				arrRight[arrLeft[b]] = arrRight[b];
				arrLeft[b] = arrRight[b] = b;
				cellVal |= wallBelow;
			}
	
			retMaze.push(cellVal);
		}
	}

	for(var b=[1]; b<=width; b++)
	{
		if((arrRight[b] != b+[1]) && (b!=width))
		{
			arrLeft[arrRight[b]] = arrLeft[b+[1]];
			arrRight[arrLeft[b+[1]]] = arrRight[b];
			arrRight[b] = b+[1];
			arrLeft[b+[1]] = b;
			cellVal = [0];
		}
		else
			cellVal = wallRight;

		retMaze.push(wallBelow | cellVal);
	}

	return retMaze;
}

January 10, 2008 08:43 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Music To My Ears

1769 views

Getting There...

2014 views

Guess Chess

1913 views

iPhone JetLag

1865 views

iPhone JetLag

1707 views
Advertisement