# Help on Power Points

#1

For some reason this code doesn’t work. Can you help me?

Here is my code:

``````# 0 is a wrong point. Positive numbers are skeletons or useful items.

spell = "VENI"
# The map of points is represented as 2d array of numbers.
wizard = hero.findNearest(hero.findFriends())
powerMap = wizard.powerMap

# This function convert grid coordinates to x-y coordinates.
def convert(row, col):
return {'x': 16 + col * 12, 'y': 16 + row * 12}

# You need loop through powerMap and find all positive numbers.
# First, loop through indexes of rows.
for i in range(len(powerMap)):
# Each row is an array. Iterate through it.
for j in range(len(powerMap[i])):
# Get the value of the i-th row and j-th column.
pointValue = powerMap[i][j]
# If it's a positive number:
positiveNumber = hero.findNearest(hero.findEnemies()) or hero.findNearest(hero.findItems())
if positiveNumber:
# Use the 'convert' function to get coordinates.
x, y = convert(row, col)
# Move there, say "VENI", fight or pick up an item.
hero.moveXY(x, y)
hero.say(spell)
``````

#2

I tried your code and I had a couple of problems, the first one I saw was a syntax error in this line:

``````x, y = convert(row, col)
``````

The function convert() returns a dictionary literal like this {‘x’: 16 + col * 12, ‘y’: 16 + row * 12}

If you want the x and y piece for later you need to store this to some variable and then get the pieces more like this.

``````mySpot = convert(row,col)
x = mySpot.x
y = mySpot.y
``````

Also you will have problems because you never set up the variables row and col to do what you want before you are calling the convert function.

Once you fix that up, you will want to use the pointValue from the powerMap somewhere in your program to decide what to do.

#3

All of what Mr-Borges said, but on top of that I would like to add something about this section of code:

``````pointValue = powerMap[i][j]
# If it's a positive number:
positiveNumber = hero.findNearest(hero.findEnemies()) or hero.findNearest(hero.findItems())
if positiveNumber:
``````

The goal here is to move to a point on the grid that is represented by a positive number. In the hints on this level it will show you what the powerMap is, which is important to understand. It’s a 2d array that will look something like this:

``````powerMap = [0,0,1,0,3]
[1,0,2,3,0]
[2,0,0,0,1]
``````

Basically, every X on your map is represented by a zero, or positive number. Now your positiveNumber variable is looking for nearby items or enemies, and moving to them. This will do nothing, because there are no items or enemies to be found unless you move to the proper X and then summon them with the spell. The pointValue variable is looping through every single element of the 2d array. So what the comment “If it’s a positive number:” is asking you to do, is to see if the pointValue variable is a positive number. And if it is, then you will need to move to that number, and say the spell.
Using my example of powerMap above, pointValue will have a different value every loop. first it will be 0, then 0, then 1, then 0, then 3, etc.

#4

Thank you. But I don’t really understand what you mean

#5

OK, this can’t work:

``````x, y = convert(row, col)
hero.moveXY(x, y)
``````

this could work

``````mySpot = convert(row,col)
x = mySpot.x
y = mySpot.y
hero.moveXY(x, y)
``````

but in order for it to work you need to set row and col to be something, your program never sets those values. You are using i and j in the for loops to step through the power map, those are your row and column values

``````positiveNumber = hero.findNearest(hero.findEnemies()) or hero.findNearest(hero.findItems())