Cursed Wonderglade (CS3)

Here is my code! Is anything wrong with it?

while True:
# Find the nearest item.
# Collect it (if it exists) only if its type isn’t “gem”.
item = hero.findNearestItem()
if item and item.type !=“gem”:
hero.moveXY(item.pos.x, item.pos.y)
# Find the nearest enemy.
enemy = hero.findNearestEnemy()
# Attack it if it exists and its type isn’t “burl”.
enemy = hero.findNearestEnemy()
if enemy and enemy.type !=“burl”:
hero.moveXY(enemy.pos.x, enemy.pos.y)
hero.attack(enemy)
pass

Please format your code by clicking the </> button to make it easier to read. Thanks :smiley:

1 Like

here is your code

while True:
    # Find the nearest item.
    # Collect it (if it exists) only if its type isn’t “gem”.
    item = hero.findNearestItem()
    if item and item.type !=“gem”:
        hero.moveXY(item.pos.x, item.pos.y)
    # Find the nearest enemy.
    enemy = hero.findNearestEnemy()
    # Attack it if it exists and its type isn’t “burl”.
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type !=“burl”:
        hero.moveXY(enemy.pos.x, enemy.pos.y)
        hero.attack(enemy)
    pass

this is what you have

 # Attack it if it exists and its type isn’t “burl”.
    enemy = hero.findNearestEnemy()
    if enemy and enemy.type !=“burl”:
        hero.moveXY(enemy.pos.x, enemy.pos.y)
        hero.attack(enemy)
    pass

change to this

    # Attack it if it exists and its type isn't "burl".
    enemy = hero.findNearestEnemy()
    if enemy:
        if enemy.type !="burl":
            hero.attack(enemy)
    pass

should look like this

while True:
    # Find the nearest item.
    # Collect it (if it exists) only if its type isn't "gem".
    item = hero.findNearestItem()
    if item:
        if item.type !="gem":
            hero.moveXY(item.pos.x, item.pos.y)
    # Find the nearest enemy.
    # Attack it if it exists and its type isn't "burl".
    enemy = hero.findNearestEnemy()
    if enemy:
        if enemy.type !="burl":
            hero.attack(enemy)
    pass
while True:
    # Find the nearest item.
    # Collect it (if it exists) only if its type isn’t “gem”.
    item = hero.findNearestItem()
    if item and item.type !=“gem”:
        hero.moveXY(item.pos.x, item.pos.y)
    # Find the nearest enemy.
    enemy = hero.findNearestEnemy()

change to this

while True:
    # Find the nearest item.
    # Collect it (if it exists) only if its type isn't "gem".
    item = hero.findNearestItem()
    if item:
        if item.type !="gem":
            hero.moveXY(item.pos.x, item.pos.y)
    # Find the nearest enemy.
    # Attack it if it exists and its type isn't "burl".
    enemy = hero.findNearestEnemy()

His work is ok. using and in one if statement will do the same thing as two if statements, it’s just more concise. pass is also unnecessary

1 Like