Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Golden Mirage help (hero is funky from my code)

So im doing golden mirage, and i did a function to sort out the bad coins. My function found out the bad coins, and it shows up in my screen, but my hero just goes back and forth and doesnt move more than a few metres from the center.

def badCoins(coins):
    badCoins = []
    for j in range(len(coins)):
        for i in range(len(coins)):
            if coins[i] is coins[j]:
                continue
            if coins[i].value == coins[j].value:
                badCoins.append(coins[i], coins[j])
    return badCoins
while True:
    coins = hero.findItems()
    bedCoins = badCoins(coins)
    for coin in coins:
        if coin not in badCoins:
            hero.move(coin.pos)

Looks like you got a little confused in your function code.You actually want to be finding the good coins.

Think of it as, If coin1 is the same value as coin2, then coin1 is a good coin…grab it! If it is not the same, then keep looking.

thanks ill do that (20 chars)

is there a way to remove an element from an array? I want to like make 2 arrays, good and bad, and when 2 coins don’t have the same value, I add them to the good array. I then compare all the good coins with each other and the bad array, and if they are the same value, I take it out. But how do i remove a thing from array?

badCoins = []
    goodCoins = []
    for j in range(len(coins)):
        for i in range(len(coins)):
            if coins[i] is coins[j]:
                continue
            if coins[i].value == coins[j].value:
                badCoins.append(coins[i], coins[j])
            else:
                goodCoins.append(coins[i], coins[j])
    for j in range(len(goodCoins)):
        for i in range(len(badCoins)):
            goodCoin = goodCoins[j]
            badCoin = goodCoins[j]
            if goodCoin.value == badCoin.value:
                #Remove good coin
                badCoins.append(goodCoin)
    return goodCoins

ok guys i solved it by making it so that if coins[j] was equal to coins[I] I would have something be false. at the end of the for loop, if it was true, that’s a good coin.