{Python}: Golden choice level-help

Hi I am really stuck in this level
here is my code

# You must collect the required amount of gold.
# The gate keeper will tell you how much you need.
# Always move in the direction of the exit.
# For each row you can take only one coin.
# Choose only one from the nearest coins in the next row.

# Distance between rows and coins.
distanceX = 4
distanceY = 6
zeroPoint = {"x": 14, "y": 14}
coinLines = 10

def makeGoldMap(coins):
    template = [[0 for j in range(2 * coinLines - 1)] for i in range(coinLines)]
    for coin in coins:
        row = int((coin.pos.y - zeroPoint.y) / distanceY)
        col = int((coin.pos.x - zeroPoint.x) / distanceX)
        template[row][col] = coin.value
    return template

# Prepare the gold map. It looks like:
# [[1, 0, 9, 0, 4],
#  [0, 1, 0, 9, 0],
#  [8, 0, 2, 0, 9]]
goldMap = makeGoldMap(hero.findItems())

# Find your path.
def findBestItem(items):
    best = None
    bestValue = 0
    itemIndex = 0
    while itemIndex < len(items):
        item = items[itemIndex]
        if item.pos.y == hero.pos.y+6:
            if item.pos.x == hero.pos.x+4:
                if item.value > bestValue:
                    best = item
                    bestValue = item.value
        elif item.pos.x == hero.pos.x-4:
            if item.value > bestValue:
                best = item
                bestValue = item.value
        itemIndex +=1
    return best
while True:
    item = findBestItem(hero.findItems())
    if item:
        while item:
            hero.move(item.pos)

please help !I don’t now what to do :unamused:

Hi qjleny,

OK, you’ve written a bit of code that looks at the next 2 coins from where you’re standing and decides which is better. Before you get too involved in the details, take a step back and try to work out a structure for how to solve this level.

A few questions for you:

  • What does goldMap actually look like? Both in the structure and the details.
  • How many different routes through the coins are there (roughly)?
  • If there were just 2 lines of coins, how would you go about working out the best route?

This level is hard, it’s worth taking time to think about the big picture. Feel free to ask more questions :slight_smile:.

Jenny

1 Like