[SOLVED] Help with golden mirage please

@AnSeDra, apparently there’s an infinite loop in this code:

while True:
    coins = hero.findItems()
    coinIndex = 0
    realCoin = None
    newCoin = None
    fakeCoin = None
    fakeCoinIndex = 0
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if newCoin == False and coinIndex == 0:
            newCoin = coin
        if newCoin:
            if coin.value !=  newCoin.value:
                newCoin = coin
            elif coin.value ==  newCoin.value:
                fakeCoin[fakeCoinIndex] = coin
                fakeCoinIndex += 1
        coinIndex += 1
    k = 0
    while k == 0:
        if  fakeCoin and (fakeCoin[fakeCoinIndex] and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]):
            realCoin = newCoin
            k = 1
        else:
            fakeCoinIndex -= 1
    if realCoin:
        hero.move(realCoin.pos)

I edited post 21 so try to correct all of it.
Does it work now?

1 Like
while True:
    coins = hero.findItems()
    coinIndex = 0
    realCoin = None
    newCoin = None
    fakeCoin = None
    fakeCoinIndex = 0
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if newCoin == False and coinIndex == 0:
            newCoin = coin
        if newCoin:
            if coin.value !=  newCoin.value:
                newCoin = coin
            elif coin.value ==  newCoin.value:
                fakeCoin[fakeCoinIndex] = coin
                fakeCoinIndex += 1
        coinIndex += 1
    k = 0
while k == 0 and fakecoin[fakeCoinIndex]:
    if (fakeCoin[fakeCoinIndex] and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]): 
        realCoin = newCoin 
        k = 1
    else: 
        fakeCoinIndex -= 1
        fakeCoinIndex -= 1
    if realCoin:
        hero.move(realCoin.pos)
    else: 
        fakeCoinIndex -= 1

he doesn’t move

1 Like

Delete it. How does it move?

no, he doesn’t (20 chars)

Could you show us your new code ?

while True:
    coins = hero.findItems()
    coinIndex = 0
    realCoin = None
    newCoin = None
    fakeCoin = None
    fakeCoinIndex = 0
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if newCoin == False and coinIndex == 0:
            newCoin = coin
        if newCoin:
            if coin.value !=  newCoin.value:
                newCoin = coin
            elif coin.value ==  newCoin.value:
                fakeCoin[fakeCoinIndex] = coin
                fakeCoinIndex += 1
        coinIndex += 1
    k = 0
    while k == 0 and fakeCoin and fakeCoin[fakeCoinIndex]:
        if (fakeCoin[fakeCoinIndex] and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]): 
            realCoin = newCoin 
            k = 1
        else: 
            fakeCoinIndex -= 1
        if realCoin:
            hero.move(realCoin.pos)

This should be outside the while loop. How can you send me the new code?

he still doesn’t move. here’s the code:

while True:
    coins = hero.findItems()
    coinIndex = 0
    realCoin = None
    newCoin = None
    fakeCoin = None
    fakeCoinIndex = 0
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if newCoin == False and coinIndex == 0:
            newCoin = coin
        if newCoin:
            if coin.value !=  newCoin.value:
                newCoin = coin
            elif coin.value ==  newCoin.value:
                fakeCoin[fakeCoinIndex] = coin
                fakeCoinIndex += 1
        coinIndex += 1
    k = 0
    while k == 0 and fakeCoin and fakeCoin[fakeCoinIndex]:
        if (fakeCoin[fakeCoinIndex] and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]): 
            realCoin = newCoin 
            k = 1
        else: 
            fakeCoinIndex -= 1
if realCoin:
    hero.move(realCoin.pos)

Put it into the while True but outsider the while k==0 loop. Can you send me the new code?

the same thing happened again, @AnSeDra. here’s the code:

while True:
    coins = hero.findItems()
    coinIndex = 0
    realCoin = None
    newCoin = None
    fakeCoin = None
    fakeCoinIndex = 0
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if newCoin == False and coinIndex == 0:
            newCoin = coin
        if newCoin:
            if coin.value !=  newCoin.value:
                newCoin = coin
            elif coin.value ==  newCoin.value:
                fakeCoin[fakeCoinIndex] = coin
                fakeCoinIndex += 1
        coinIndex += 1
    k = 0
    while k == 0 and fakeCoin and fakeCoin[fakeCoinIndex]:
        if (fakeCoin[fakeCoinIndex] and newCoin) and (newCoin != fakeCoin[fakeCoinIndex]): 
            realCoin = newCoin 
            k = 1
        else: 
            fakeCoinIndex -= 1
    if realCoin:
        hero.move(realCoin.pos)

Delete this.
Are you sure that the array fakeCoin contains all of the fake coins?

i think it does … but does it?

After you removed that does it work?

no, because it “isn’t defined”

This is how I completed it. First I went with index i through the coins array than put coinA=coins[i] and I made k =0. After that I went with index j through the coins array then put coinB=coins[j] and if coinA.value==coinB.value and i != j, then I made k=1 and after I checked all of the coins with the j index k is still 0, then moveXY to the coinA’s posision. Do you understand?

can you have it in pieces please?

while True:
    coins=hero.findItems()
    i=0
    while i < len(coins):
        coinA = coins[i]
        j = 0
        k=0
        while j < len(coins):
            coinB = coins[j]
            # if the coinA and CoinB's values are equal and i != j, make k=1 and break
            j += 1
        if k==0:
            #here use moveXY to pick up the coinA
        i += 1

Do you need any more assistance at this level?

coinB isn’t defined (20)

Put coinB as coins[j]. Do you need any more assistance at this level?