deadend removal need help

Blitz3D Forums/Blitz3D Programming/deadend removal need help

Schragnasher(Posted 2007) [#1]
Ok so i'm building a 3d roguelike. Iv gotten the random dngeons going quite handily. I'm working on some routines to clean it up. Im trying to write a function to remove dead ends and for the most part this works.
2=floor
0=emptyspace
minimum hallway length is 3

;//////remove deadends: doesnt completly work but helps To clean things up/////////
	For x=1 To dungeonheight-1
		For y=1 To dungeonwidth-1
			If map(x,y)=2 Then
				emptycount=0
				For x2=x-1 To x+1
					For y2=y-1 To y+1
						If map(x2,y2)=0 Then emptycount=emptycount+1
					Next
				Next
				If emptycount>=7 Then 
					For x2=x-1 To x+1
						For y2=y-1 To y+1
							map(x2,y2)=0
						Next
					Next
					y=1
					x=1
					Exit
				End If
				
			End If
		Next
	Next
	;////////////////////////////////////////////////////////////


The problem is that i keep ending up with stragglers of one piece on the end of some of the hallways.
it is supposed to work like so
1. run through every point on the grid
2. check if its a floor tile
3. if not move on
4. if so, count the number of empty spaces around it
5. if there are 7 empty spaces, delete the floor tile by setting the tile and all of its surrounding grid spaces to empty spaces. (this SHOULD remove any stragglers as it also removes the last piece connected to a room that DOESN'T have 7 surrounding empty spaces) Then restart from the beginning(im sure this is a bad way to go about this part, but it was a brute force way to be sure i get every dead end)
yet i still get 1 tile stragglers on some of my rooms

help is appreciated

edit: marked an example below, according to my code i dont think such a floor tile should exist



Stevie G(Posted 2007) [#2]
According to your code it should be there. There are only 5 empty spaces surounding it.

Stevie


Schragnasher(Posted 2007) [#3]
wait i see it now, if my minimum is 3, the third space out is removing itself AND space 2....thus leaving space 1 with 5. lol ok thanks for pointing out the obvious. :) so its happening when the corridor length is a odd value...