I am stuck on the Flawless Pairs problem with Python. My character gets stuck at the first moveXY. I am not sure if it a problem with my code, my browser, or possibly the level.
Here is the revelant part of my code:
hero.moveXY(gemPair[0].pos.x, gemPair[0].pos.y)
hero.moveXY(40,44)
hero.moveXY(gemPair[1].pos.x, gemPair[1].pos.y)
hero.moveXY(40,44)
Hm, your code works fine for me. I suppose it’s an equipment problem or unlucky seed or a bug. Could you say your codecombat username and I’ll research the problem for your case.
Hm. I see a problem. It’s a pet, I’m not sure how, but it affects on the level. It’s definitely a bug, however, you can pass this level by removing the pet (while I trying to fix the problem with a pet).
I couldn’t get haste either so I used the moved the Y method (closer to gems) but you can also change characters to one with more speed. I used Tharin at first and failed miserably so then I changed to Pender Spellbane and Arryn Stonewall and both of those completed the level without the haste spell. It didn’t matter about the Pet. I do have fast boots (boots of Leaping +2M/S).
My code isn’t working. For some reason My character is just moving around on the spot. I cannot figure out how to fix that. Can you please help me debug it? Here is my non-working code and a photo of the items that I am using. Thanks in advance.
# Collect 4 pairs of gems.
# Each pair must contain equal valued gems.
# This function returns two items with the same value.
def findValuePair(items):
# Check each possible pair in the array.
# Iterate indexes 'i' from 0 to the last one.
for i in range(len(items)):
itemI = items[i];
# Iterate indexes 'j' from 0 to the last.
for j in range(len(items)):
# If it's the same element, then skip it.
if i == j:
continue
itemJ = items[j];
# If we found a pair with two equal gems, then return them.
if itemI.value == itemJ.value:
return [itemI, itemJ]
# Return an empty array if no pair exists.
return None
while True:
gems = hero.findItems()
gemPair = findValuePair(gems)
# If the gemPair exists, collect the gems!
if gemPair:
gemA = gemPair[0]
gemB = gemPair[1]
# Move to the first gem.
hero.move(gemA.pos)
# Return to get the haste from the wizard.
hero.moveXY(40, 44)
# Then move to the second gem.
hero.move(gemB.pos)
# Return to get the haste from the wizard.
hero.moveXY(40, 44)
pass
You shouldn’t use the move method here. Just use moveXY. When you use the moveXY method, the code will have the hero move to the target position and it will not do anything else until it arrives there. When you use the move method, the code has the hero take a single step in the direction of the target, and then checks to see if there’s anything else that it can be doing, in this case that means checking the next line of code, which is the moveXY method.
Just stick to the moveXY method and the code will work.