Can you help me? I just do not know what is wrong with my code. Here it is:
# Welcome to Gridmancer!
# A relic of days long past, the puzzle returns!
# Your task is to collect all the coins.
# You are given special methods to help with hero task.
# hero.addRect(x, y, w, h) places a rectangle to collect coins.
# hero.removeRect(x, y) removes a previously added rectangle at the point.
# hero.navGrid is (basically) a 2-dimensional array containing "Coin" or "Wall"
# You must collect all coins under rectangles
# Rectangles cannot collide with themselves or walls
# You need to make at most 55 rectangles to beat hero level!
#hero.addRect(0, 18, 4, 2)
#hero.addRect(0, 0, 4, 3)
map = hero.navGrid
for i in range(20):
addRect(i)
def addRect(row):
y = row
done = 0
for col in map[row]:
pos = map[row][col]
if pos == "Coin" and done == 0:
x = col
w = 1
done = 1
elif pos == "Coin":
w += 1
elif pos == "Wall" and done == 1:
done = 0
hero.addRect(x, y, w, 1)
if w == 20:
hero.addRect(x, y, 20, 1)