updates plz
This commit is contained in:
73
main.py
73
main.py
@ -46,6 +46,54 @@ def generate_world(seed):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
def terrain_matches(cell1, cell2):
|
||||||
|
return cell1["is_land"] == cell2["is_land"] or cell1["is_water"] == cell2["is_water"]
|
||||||
|
|
||||||
|
def group_terrain(world):
|
||||||
|
world_terrain_without_group = []
|
||||||
|
group_id = 0
|
||||||
|
for y in range(world_h):
|
||||||
|
row = []
|
||||||
|
for x in range(world_w):
|
||||||
|
cell = world[y][x]
|
||||||
|
terrain = {
|
||||||
|
"v": cell,
|
||||||
|
"x": x,
|
||||||
|
"y": y,
|
||||||
|
"is_land": cell > water,
|
||||||
|
"is_water": cell <= water
|
||||||
|
}
|
||||||
|
row.append(terrain)
|
||||||
|
world_terrain_without_group.append(row)
|
||||||
|
|
||||||
|
world_terrain = []
|
||||||
|
for y in range(world_h):
|
||||||
|
row = []
|
||||||
|
for x in range(world_w):
|
||||||
|
cell = world_terrain_without_group[y][x]
|
||||||
|
north = world_terrain_without_group[y - 1][x] if y > 0 else None
|
||||||
|
south = world_terrain_without_group[y][x] if y < world_h else None
|
||||||
|
east = world_terrain_without_group[y][x] if x < world_w else None
|
||||||
|
west = world_terrain_without_group[y][x - 1] if x > 0 else None
|
||||||
|
if north and terrain_matches(cell, north):
|
||||||
|
print(f"{x}:{y} - north")
|
||||||
|
elif east and terrain_matches(cell, east):
|
||||||
|
print(f"{x}:{y} - east")
|
||||||
|
elif south and terrain_matches(cell, south):
|
||||||
|
print(f"{x}:{y} - south")
|
||||||
|
elif west and terrain_matches(cell, west):
|
||||||
|
print(f"{x}:{y} - west")
|
||||||
|
# else:
|
||||||
|
# print("new group")
|
||||||
|
# cell["group_id"] = group_id
|
||||||
|
# group_id += 1
|
||||||
|
#print(cell)
|
||||||
|
row.append(cell)
|
||||||
|
world_terrain.append(row)
|
||||||
|
|
||||||
|
print(f"Number of groups: {group_id}")
|
||||||
|
return world_terrain
|
||||||
|
|
||||||
def add_home(world):
|
def add_home(world):
|
||||||
print("Choosing home location")
|
print("Choosing home location")
|
||||||
home = (0, 0)
|
home = (0, 0)
|
||||||
@ -83,7 +131,14 @@ def distribution(world):
|
|||||||
return above_water / total
|
return above_water / total
|
||||||
|
|
||||||
def print_map(world, home):
|
def print_map(world, home):
|
||||||
|
print(" ", end="", flush=True)
|
||||||
|
for x in range(world_w):
|
||||||
|
to_print = str(x) + " " if x < 10 else x
|
||||||
|
print(to_print, end="", flush=True)
|
||||||
|
print("")
|
||||||
for y in range(world_h):
|
for y in range(world_h):
|
||||||
|
to_print = str(y) + " " if y < 10 else y
|
||||||
|
print(to_print, end="", flush=True)
|
||||||
for x in range(world_w):
|
for x in range(world_w):
|
||||||
cell = world[y][x]
|
cell = world[y][x]
|
||||||
if home[0] == x and home[1] == y:
|
if home[0] == x and home[1] == y:
|
||||||
@ -102,6 +157,21 @@ def print_map(world, home):
|
|||||||
print(colored(block, "white"), end="", flush=True)
|
print(colored(block, "white"), end="", flush=True)
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
|
def print_terrain(world):
|
||||||
|
colours = ["grey", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]
|
||||||
|
print(" ", end="", flush=True)
|
||||||
|
for x in range(world_w):
|
||||||
|
to_print = str(x) + " " if x < 10 else x
|
||||||
|
print(to_print, end="", flush=True)
|
||||||
|
print("")
|
||||||
|
for y in range(world_h):
|
||||||
|
to_print = str(y) + " " if y < 10 else y
|
||||||
|
print(to_print, end="", flush=True)
|
||||||
|
for x in range(world_w):
|
||||||
|
cell = world[y][x]
|
||||||
|
print(colored(block, colours[cell["group_id"]]), end="", flush=True)
|
||||||
|
print("")
|
||||||
|
|
||||||
world = generate_world(seed)
|
world = generate_world(seed)
|
||||||
i = 1
|
i = 1
|
||||||
land_percentage = distribution(world)
|
land_percentage = distribution(world)
|
||||||
@ -110,8 +180,11 @@ while (land_percentage < 0.25 or 1 - land_percentage < 0.25):
|
|||||||
land_percentage = distribution(world)
|
land_percentage = distribution(world)
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
||||||
|
world_terrain = group_terrain(world)
|
||||||
|
|
||||||
print(str(i - 1) + " seed iterations")
|
print(str(i - 1) + " seed iterations")
|
||||||
|
|
||||||
home = add_home(world)
|
home = add_home(world)
|
||||||
dock = add_dock(world, home)
|
dock = add_dock(world, home)
|
||||||
print_map(world, home)
|
print_map(world, home)
|
||||||
|
print_terrain(world_terrain)
|
||||||
|
Reference in New Issue
Block a user