okay so im making a dictionary map where it uses different symbols to refrence trees and mountains ect.
Anyways in Line 19 is where im trying to strip part of the string
the symbols are showing up as [' ▲'] instead of just ▲
import random
def createMap(size):
m = {}
m["grid"] = []
m["size"] = size #map size (square)
#Make the empty grid
for x in range(m["size"]):
m["grid"].append([]) #make it a size-by-size 2D list
#fill it with the fillCharacter
for row in range(m["size"]):
for x in range(m["size"]):
symbolList = [" ≈", " ▲", " ♣", " ░", " ▒"]
weights = fillMap(row,x,m)
weightedBiome = random.choices(symbolList, weights, k=1)
weightedBiome[0].strip(']')
try:
m["grid"][row].append(weightedBiome)
except IndexError:
continue
return m
def fillMap(x,y,m):
weights = (1,1,1,1,1)
try:
if m["grid"][y][x-1] == " ≈":
weights = (4, 2, 2, 0, 2)
elif m["grid"][y][x-1] == " ▲":
weights = (2, 3, 2, 2, 1)
elif m["grid"][y][x-1] == " ♣":
weights = (2, 2, 4, 0, 2)
elif m["grid"][y][x-1] == " ░":
weights = (0, 2, 0, 5, 2)
elif m["grid"][y][x-1] == " ▒":
weights = (2, 1, 2, 3, 2)
if m["grid"][y-1][x-1] == " ≈":
weights += (4, 2, 2, 0, 2)
elif m["grid"][y-1][x-1] == " ▲":
weights += (2, 3, 2, 2, 1)
elif m["grid"][y-1][x-1] == " ♣":
weights += (2, 2, 4, 0, 2)
elif m["grid"][y-1][x-1] == " ░":
weights += (0, 2, 0, 5, 2)
elif m["grid"][y-1][x-1] == " ▒":
weights += (2, 1, 2, 3, 2)
if m["grid"][y-1] == " ≈":
weights += (4, 2, 2, 0, 2)
elif m["grid"][y-1] == " ▲":
weights += (2, 3, 2, 2, 1)
elif m["grid"][y-1] == " ♣":
weights += (2, 2, 4, 0, 2)
elif m["grid"][y-1] == " ░":
weights += (0, 2, 0, 5, 2)
elif m["grid"][y-1] == " ▒":
weights += (2, 1, 2, 3, 2)
if x < m["size"]:
if m["grid"][y-1][x+1] == " ≈":
weights += (4, 2, 2, 0, 2)
elif m["grid"][y-1][x+1]== " ▲":
weights += (2, 3, 2, 2, 1)
elif m["grid"][y-1][x+1] == " ♣":
weights += (2, 2, 4, 0, 2)
elif m["grid"][y-1][x+1] == " ░":
weights += (0, 2, 0, 5, 2)
elif m["grid"][y-1][x+1] == " ▒":
weights += (2, 1, 2, 3, 2)
# if m["grid"][y][x-1] or m["grid"][y-1][x-1] or m["grid"][y-1] or m["grid"][y-1][x+1] == "▒":
#weights = weights(1,1,1,1,0)
except IndexError:
pass
return weights
def displayMap(m):
#Top label
listNum = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
count = 1
solution = (f" │{count}")
print("0 ", end="")
for x in range(m["size"]):
if count in listNum:
solution = (f" │{count}")
elif count == 0:
solutin = (f" {count} ")
else:
solution = (f"│{count}")
count += 1
print(solution, end="")
print()
#Each row
count = 1
listNum = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
solution = count
for row in m["grid"]:
if count in listNum:
solution = (f"{count} ")
else:
solution = count
print(solution, end="")
for col in row:
print(col, end="")
count += 1
print()
#Add something to the map
def add(m, row, col, symbol):
m["grid"][row][col] = symbol
def main():
mapSize = 30
halfMap = round(mapSize / 2)
room1 = createMap(mapSize)
add(room1, halfMap, halfMap, " ⌂")
displayMap(room1)
main()