testing/ folder

This commit is contained in:
Suguivy 2023-03-20 18:50:40 +01:00
parent f5b7d0f5e1
commit fa76489ed4
1 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,96 @@
import random
def generate(width, height, edgeRows, edgeCols, seed=None):
grid = []
for row in range(height):
grid.append([])
for tile in range(width):
grid[row].append('#')
#grid = [['#'] * width] * height
edges = set()
for i in range(edgeCols):
for j in range(edgeRows):
x = i * (width // edgeCols)
y = j * (height // edgeRows)
edges.add((x,y))
not_connected = set(edges)
connected = set()
connected.add(next(iter(not_connected)))
while len(not_connected) > 0:
(dx, dy) = not_connected.pop()
(ox, oy) = next(iter(connected))
connected.add((dx, dy))
directions = ['N', 'S', 'W', 'E']
direction = random.choice(directions)
valid_direction = False
while not valid_direction:
direction = random.choice(directions)
if direction == 'N':
valid_direction = oy >= dy
if direction == 'S':
valid_direction = oy <= dy
if direction == 'W':
valid_direction = ox >= dx
if direction == 'E':
valid_direction = ox <= dx
if direction == 'N':
for y in range(dy, oy+1):
grid[y][ox] = '.'
(minX, maxX) = (ox, dx) if ox < dx else (dx, ox)
for x in range(minX, maxX):
grid[dy][x] = '.'
if direction == 'S':
for y in range(oy, dy+1):
grid[y][ox] = '.'
(minX, maxX) = (ox, dx) if ox < dx else (dx, ox)
for x in range(minX, maxX):
grid[dy][x] = '.'
if direction == 'W':
for x in range(dx, ox+1):
grid[oy][x] = '.'
(minY, maxY) = (oy, dy) if oy < dy else (dy, oy)
for y in range(minY, maxY):
grid[y][dx] = '.'
if direction == 'E':
for x in range(ox, dx+1):
grid[oy][x] = '.'
(minY, maxY) = (oy, dy) if oy < dy else (dy, oy)
for y in range(minY, maxY):
grid[y][dx] = '.'
for (x, y) in edges:
grid[y][x] = '.'
for row in grid:
for tile in row:
print(tile, end='')
print()
generate(80, 20, 6, 8)
"""
Generate points at random positions
Pick point X and another random point without connections.
"""
"""
################################################################
################################################################
#############################......#############################
###########################...####.#############################
#################################....#####......################
##############################..#.##...##.......################
###############################...####....#.....################
################################################################
################################################################
################################################################
################################################################
"""