# Help on Gridmancer Redux

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!
# 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!

map = hero.navGrid

for i in range(20):

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
if w == 20:

``````

Is it like this?

``````# Welcome to Gridmancer!
# A relic of days long past, the puzzle returns!
# You are given special methods to help with this task.
# this.addRect(x, y, w, h) places a rectangle to collect coins.
# this.removeRect(x, y) removes a previously added rectangle at the point.
# this.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 this level!
array_greed = hero.navGrid

def getRectngle(index1, index2):
width = 0
height = 0
if array_greed[index1][index2] == 'Coin':
indy = index2
indx = index1
for x in range(indx, lenght_xy):
if array_greed[x][indy] == 'Coin':
width = width + 1
else:
break
for y in range(indy, lenght_xy):
width_tmp = 0
for x in range(indx, lenght_xy):
width_tmp = width_tmp + 1
# hero.debug(x+'_'+y+'_'+array_greed[x][y])
if array_greed[x][y] != 'Coin':
return_object = {'x': index1, 'y': index2, 'width': width, 'height': height}
return return_object
elif (width_tmp >= width):
height = height + 1
break
return_object = {'x': index1, 'y': index2, 'width': width, 'height': height}
return return_object
else:
return None
# return {x:,y:,w:,h:}

rect = []  # {x, y, w, h}
lenght_xy = 20
for x in range(lenght_xy):
for y in range(lenght_xy):
rectg = getRectngle(x, y)
if rectg:
# hero.say([rectg.x, rectg.y, rectg.width, rectg.height])
rect.push(rectg)
for xi in range(rectg.x, rectg.x + rectg.width):
for yi in range(rectg.y, rectg.y + rectg.height):
array_greed[xi][yi] = 'Got'
# hero.say(xi+'_'+yi+'_'+array_greed[xi][yi])
# hero.say(array_greed[0])
# hero.say([rect[0].x, rect[0].y, rect[0].width, rect[0].height])
index = 0
break_i = 56
for rec in rect:
if break_i == index:
hero.say([rect[index].x, rect[index].y, rect[index].width, rect[index].height])
break
index = index + 1
``````
1 Like

What do you mean? What is with that code?

But I also have problems!

No, I think it is not.

I will try it again(20 chars)

what is the link(to the game)

it only lets me play javascript

sorry(20 characters needed)

Can’t you press Change hero or language and select phyton?

no i am not on that level because I played by link not by level

Ok. Thanks for trying, @Jeremy_Yu! Anybody else?

But did it work did you try it?

Now I am doing that.

Did it work if it does i will delete it

i didnt did it?(20 chars)

It works. Please delete it. Thanks for help, but I want to learn the strategy myself with my own code.

did it work it failed right?

It worked the one you sent me