"Flawless Pairs" Python

Hello everyone! I’m new here and I believe I have a problem with the level “Flawless Pairs” in Cloudrip Mountain. Sorry if I didn’t format correctly, here’s my code :blush:

# 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

I get stuck in one place, trying to go to get a gem but also trying to get back to get the “haste” from the wizard. My coding isn’t very well, thanks for your help!

1 Like

apparently the hero.move(gemA.pos) isn’t functioning, the command is not moving your hero, try using hero.moveXY(gemA.pos.x, gemA.pos.y), if i helped, please mind doing me a favor by checking the check mark by my post to mark it as the solution.
also, welcome to the discourse @vivian_lizard! nice job formatting your code right, make sure to check out the rules over here : Welcome to CodeCombat Discourse Forums! - CodeCombat Discourse

2 Likes

Thank you so much :smiling_face_with_three_hearts: !

1 Like

thats just what us discourse members do,

1 Like

I’ll try to do that when I’m as experienced as you :laughing:

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.