Without finding what the actual problem was. Your code is very repetitive.
In the findBestItem method.
if item.value / hero.distanceTo(item) > bestValue: == if valueOverDistance(item) > bestValue:
Honestly it would be better if you created a variable to hold this value since you then call the method to assign a value to bestValue. Knock out two birds with one stone and put the value in a holding variable before the if statement. You could then have
Holding_Variable = valueOverDistance(item)
if Holding_Variable > bestValue:
bestValue = Holding_Variable
You also pass in an array called items but then you create a new variable called items wich holds the same exact value as the passed in variable. Right above the while statement.
You’re setting items = hero.findItems() in the function findBestItem, but why do you need to do that? You’re already sending the items variable to the function as a parameter.
If that doesn’t fix it, please provide some more details as to what is happening when you run the code. The code looks good to me, except findBestItem could use some work in a couple places. For instance, you’re using item.value / hero.distanceTo(item), but that’s exactly what your valueOverDistance function returns. This part shouldn’t make a big difference, though.
Everytime you press the submit button it generates a new set of monsters. Its to keep everything random so you cant perfect the level when you keep pressing run. If you submit it again you may or may not fail.