samedi 5 novembre 2016

Python booleans not triggering if block? [on hold]

I have an if block that needs to be triggered when a certain variable is False. For some reason, it's never triggering. Could someone help me out?

The program is a tile based map generator. If a lake tile is not on the top edge of the map, it should have a 60% chance of spreading up (making the tile above it water.)

    #Add lake points to the map.
for k in range(30): #Try 30 times to add water to a tile.
    tileselect = random.randint(1, mapwidth ** 2)
    maybewater = random.randint(0, 9)
    if maybewater == (0 or 1):  #20% chance of water.
        map[tileselect] = tileset['WATER']
        lakes.append(tileselect)

for l in lakes:
    #Determine if the lake is on any edges.
    lakeonrightedge = False
    lakeonleftedge = False
    lakeontopedge = False
    lakeonbottomedge = False
    if l % mapwidth == 0:
        lakeonrightedge = True
    if l % mapwidth == 1:
        lakeonleftedge = True
    if l in range(1, mapwidth):
        lakeontopedge = True
    if l in range(len(map) - mapwidth - 1, len(map) - 1):
        lakeonbottomedge = True

    #Spread the water.
    #Spread up 1?
    if lakeontopedge:
        pass    #Don't spread up if we're already on the top edge.
    else:
        spreadupchance = random.randint(0, 9)
        if spreadupchance == (0, 1, 2, 3, 4, 5):    #60% chance to spread up.
            print ('Spread lake ' + str(l) + ' up.')
            map[(l-7)] = tileset['WATER']
        else:
            pass

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire