Need ideas - detecting a "closed loop" on tilemap
by Paul Fountain · in Torque Game Builder · 04/17/2006 (10:42 pm) · 6 replies
I am working on a clone of a very old arcade game called "Rampart". Basically the idea is you use Tetris-like pieces to build a castle. You place the pieces until you wall in a number of flags, and then the enemy pirate ships attack your castle. I have the basic block movement, rotation, and placement working thanks to the Tetris tutorial on TDN. Screenshot below:

Now to my question - how can I run a check on my tilemap to detect when I have completed a castle or a "closed loop" as shown in the screenshot? And also how would I determine the number of flags enclosed within the castle to calculate the player's score? I'm not looking for exact code here - just a general description of the technique and maybe a little pseudocode would be enough to get me going.

Now to my question - how can I run a check on my tilemap to detect when I have completed a castle or a "closed loop" as shown in the screenshot? And also how would I determine the number of flags enclosed within the castle to calculate the player's score? I'm not looking for exact code here - just a general description of the technique and maybe a little pseudocode would be enough to get me going.
#2
04/17/2006 (11:13 pm)
Excellent starting point, Tom. It'll take me some time to digest that information and make it work with my game. I'll try to post the code I come up with when I figure it out.
#3
04/19/2006 (9:26 pm)
I'm close. I can practically smell it. But I'm having some trouble with this code:// GetCheckTiles() returns a ScriptObject of class CHECKTILES. This is a 6x6 array similar
// to the SHAPE class, but it will define for any given shape: which tiles are adjacent to
// a block in that shape? Those are the tiles we need to run a CastleCheck() on.
%checktiles = new ScriptObject() { class = "CHECKTILES"; }
%checktiles = GetCheckTiles($GAME::CurrentShape); ***SYNTAX ERROR HERE***
...
function GetCheckTiles(%shape)
{
// create a checktiles object and initialize it with zeros
%checktiles = new ScriptObject() { class = "CHECKTILES"; }
for (%x=0;%x<6;%x++)
for (%y=0;%y<6;%y++)
%checktiles.check[%x,%y] = 0
// examine the shape and set checktiles accordingly
for (%x=1;%x<5;%x++)
for (%y=1;%y<5;%y++)
if (%shape.block[%x-1,%y-1] == 1)
{
// if this tile in the shape is a block, set every adjacent tile in the
// checktiles to 1, except for other blocks.
%checktiles.check[%x-1,%y] = 1 - %shape.block[%x-2,%y-1];
%checktiles.check[%x-1,%y+1] = 1 - %shape.block[%x-2,%y];
%checktiles.check[%x,%y+1] = 1 - %shape.block[%x-1,%y];
%checktiles.check[%x+1,%y+1] = 1 - %shape.block[%x,%y];
%checktiles.check[%x+1,%y] = 1 - %shape.block[%x,%y-1];
%checktiles.check[%x+1,%y-1] = 1 - %shape.block[%x,%y-2];
%checktiles.check[%x,%y-1] = 1 - %shape.block[%x-1,%y-2];
%checktiles.check[%x-1,%y-1] = 1 - %shape.block[%x-2,%y-2];
}
return %checktiles;
}The console is telling me I have a syntax error on that line I have marked above. How do write a function that returns a ScriptObject() ?
#4
04/19/2006 (9:46 pm)
I think you are missing a semicolon? %checktiles = new ScriptObject() { class = "CHECKTILES"; };
#5
04/19/2006 (9:58 pm)
DUH yes I realized that a few minutes later. In the meantime, I changed %checktiles to a global variable and modified my GetCheckTiles() function to just operate on the global. So one problem down, and on to another ... I seem to be crashing after placing a few shapes.
#6
04/19/2006 (11:57 pm)
Well after setting up a debug version of T2D, and looking at the problem for a while, I seem to be hitting an endless loop with my recursive function CastleCheck(). T2D is not "crashing" per se, it is just exiting cleanly when it detects the endless loop. Is there any way to stop the engine just before it exits, so I can look at the configuration of blocks that is causing the endless loop?
Associate Tom Spilman
Sickhead Games
(and i love Rampart)