I am trying to randomly generate land masses, represented by ASCII art, using Python. I have the following code which either generates mostly water or mostly land. How could I achieve my end goal?
from random import *
water = "."
land = "#"
waterChance = 40
landChance = 100 - waterChance
width = 40
height = 20
prevTile = water
level = []
for i in range(height):
level += [[]]
for j in range(width):
# change to ternary
if prevTile == water:
waterChance += 10
elif prevTile == land:
waterChance -= 10
if(waterChance == 50):
waterChance += 5
tile = randrange(1,101)
if tile > waterChance:
print(land, end='')
prevTile = land
elif tile <= waterChance:
print(water, end='')
prevTile = water
print()
Aucun commentaire:
Enregistrer un commentaire