Optimization for the loop placing algorithm
This commit is contained in:
		@@ -21,37 +21,38 @@ DEFAULT_PARAMS = {
 | 
			
		||||
    "large_circular_room": .10,
 | 
			
		||||
    "circular_holes": .5,
 | 
			
		||||
    "loop_tries": 40,
 | 
			
		||||
    "loop_max": 5,
 | 
			
		||||
    "loop_max": 8,
 | 
			
		||||
    "loop_threshold": 15,
 | 
			
		||||
    "spawn_per_region": [1, 2],
 | 
			
		||||
    "room_chances" : {
 | 
			
		||||
        "circular" : 3,
 | 
			
		||||
        "chunks" : 2,
 | 
			
		||||
        "circular" : 1,
 | 
			
		||||
        "chunks" : 1,
 | 
			
		||||
        "rectangle" : 1,
 | 
			
		||||
        },
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
def dist(level, y1, x1, y2, x2):
 | 
			
		||||
def test_dist(level, y1, x1, y2, x2, threshold):
 | 
			
		||||
    """
 | 
			
		||||
    Compute the minimum walking distance between points (y1, x1) and (y2, x2) on a Tile grid
 | 
			
		||||
    Returns whether the minimum walking distance between points (y1, x1) and 
 | 
			
		||||
    (y2, x2) on the Tile grid level is greater than threshold
 | 
			
		||||
    """
 | 
			
		||||
    # simple breadth first search
 | 
			
		||||
    copy = [[t for t in row] for row in level]
 | 
			
		||||
    dist = -1
 | 
			
		||||
    queue, next_queue = [[y1, x1]], [0]
 | 
			
		||||
    while next_queue:
 | 
			
		||||
    while next_queue and dist < threshold:
 | 
			
		||||
        next_queue = []
 | 
			
		||||
        dist += 1
 | 
			
		||||
        while queue:
 | 
			
		||||
            y, x = queue.pop()
 | 
			
		||||
            copy[y][x] = Tile.EMPTY
 | 
			
		||||
            if y == y2 and x == x2:
 | 
			
		||||
                return dist
 | 
			
		||||
                return False
 | 
			
		||||
            for y, x in Map.neighbourhood(copy, y, x):
 | 
			
		||||
                if copy[y][x].can_walk():
 | 
			
		||||
                    next_queue.append([y, x])
 | 
			
		||||
        queue = next_queue
 | 
			
		||||
    return -1
 | 
			
		||||
    return True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Generator:
 | 
			
		||||
@@ -148,7 +149,7 @@ class Generator:
 | 
			
		||||
                return True
 | 
			
		||||
            # if adding the path would make the two tiles significantly closer
 | 
			
		||||
            # and its sides don't touch already placed terrain, build it
 | 
			
		||||
            if dist(level, y1, x1, y2, x2) < 20 and verify_sides():
 | 
			
		||||
            if test_dist(level, y1, x1, y2, x2, 20) and verify_sides():
 | 
			
		||||
                y, x = y1 + dy, x1 + dx
 | 
			
		||||
                while level[y][x] == Tile.EMPTY:
 | 
			
		||||
                    level[y][x] = Tile.FLOOR
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user