Блэквудский лес. Подслеповатый Бурл

Помогите разобраться. Написал код, понимаю что нужно написать функцию takeItem, но как это и где сделать не понимаю. Пробовал писать по разному - не получается. На сколько я понимаю тело функции изменять нельзя. Первую функцию так же нельзя менять. Во второй нужен один аргумент. Так в какую часть тогда вставлять?

# Собери монеты и сбеги, пока бурл не нашёл тебя.

# This function allows your hero take an item.
def takeItem(item):
    hero.moveXY(item.pos.x, item.pos.y)

# Напиши функцию `checkTakeRun` с одним параметром.
# If the item exists, use "takeItem" function to take it.
# Двигайся на исходную точку (зелёная отметка), вне зависимости от наличия предмета.
def checkTakeRun(coin):
    hero.moveXY(40, 12)
    


# Не меняй этот код.
while True:
    hero.moveXY(16, 56)
    coin = hero.findNearestItem()
    checkTakeRun(coin)
    hero.moveXY(64, 56)
    coin = hero.findNearestItem()
    checkTakeRun(coin)
    
type or paste code here

Можете дать ссылку на уровень?

https://codecombat.com/play/level/short-sighted-burl?

Итак, у вас уже есть функция takeItem(). Вам необходимо включить takeItem() в функцию checkTakeRun(). Вам нужно найти элемент, взять его, если он есть, а затем вернуться в функцию checkTakeRun()

Okay, so you already have the function takeItem(). You need to incorporate the takeItem() into the checkTakeRun() function. You need to find an item, take the item if there is an item and then move back in the checkTakeRun() function

Итак, вам нужно сначала определить элемент. Например, item = hero.findNearestItem И если есть предмет, вы должны использовать функцию takeItem (item), чтобы взять предмет и бегать к (40,12).
Если предмета нет, просто бегите к (40,12).

So you have to first define item. Like item = hero.findNearestItem And if there is an item, you would use takeItem(item) function to take the item, and run to (40,12).
If there isn’t an item, just run to (40,12).

Lydia

1 Like

Не могу понять причину, почему герой не берет монету? Хотелось бы понять что не так в моем коде? Preformatted text

Собери монеты и сбеги, пока бурл не нашёл тебя.

This function allows your hero take an item.

def takeItem(item):
hero.moveXY(item.pos.x, item.pos.y)

Напиши функцию checkTakeRun с одним параметром.

If the item exists, use “takeItem” function to take it.

Двигайся на исходную точку (зелёная отметка), вне зависимости от наличия предмета.

def checkTakeRun(coin):
hero.moveXY(40, 12)
coin = hero.findNearestItem()
if coin:
takeItem(coin)
else:
hero.moveXY(40, 12)

Не меняй этот код.

while True:
hero.moveXY(16, 56)
coin = hero.findNearestItem()
checkTakeRun(coin)
hero.moveXY(64, 56)
coin = hero.findNearestItem()
checkTakeRun(coin)

# Собери монеты и сбеги, пока бурл не нашёл тебя.

# This function allows your hero take an item.
def takeItem(item):
    hero.moveXY(item.pos.x, item.pos.y)

# Напиши функцию `checkTakeRun` с одним параметром.
# If the item exists, use "takeItem" function to take it.
# Двигайся на исходную точку (зелёная отметка), вне зависимости от наличия предмета.
def checkTakeRun(coin):
    hero.moveXY(40, 12)
    coin = hero.findNearestItem()
    if coin:
        takeItem(coin)
    else:
        hero.moveXY(40, 12)


# Не меняй этот код.
while True:
    hero.moveXY(16, 56)
    coin = hero.findNearestItem()
    checkTakeRun(coin)
    hero.moveXY(64, 56)
    coin = hero.findNearestItem()
    checkTakeRun(coin)
    
type or paste code here

Проблема в том, что вы не определяете переменную “item”. Вы должны сделать item = hero.findNearestItem после def takeItem (item)Вы также должны добавить if item: hero.moveXY (item.pos.x, item.pos.y)

# Собери монеты и сбеги, пока бурл не нашёл тебя.

# This function allows your hero take an item.
def takeItem(item):
    #вставить item = hero.findNearestItem Вот
    #if item:
    hero.moveXY(item.pos.x, item.pos.y) #сделать отступ в этой строке

The problem is that you are not defining the variable “item”. You must do item = hero.findNearestItem after def takeItem(item) You should also add if item: hero.moveXY(item.pos.x, item.pos.y)

1 Like

@11180 Проблема здесь в вашей функции checkTakeRun(). Замените слово монета на предмет.

The problem here is your checkTakeRun() function. Take the word coin, and replace it with the word item.

1 Like

До сих пор не могу решить задачу. Не понимаю почему не работает?

# Собери монеты и сбеги, пока бурл не нашёл тебя.

# This function allows your hero take an item.
def takeItem(item):
   hero.moveXY(item.pos.x, item.pos.y)

# Напиши функцию `checkTakeRun` с одним параметром.
# If the item exists, use "takeItem" function to take it.
# Двигайся на исходную точку (зелёная отметка), вне зависимости от наличия предмета.
def checkTakeRun(item):
   hero.moveXY(40, 12)
   item = hero.findNearestItem()
   if item:
       hero.moveXY(40, 12)
   else:
       hero.moveXY(40, 12)

# Не меняй этот код.
while True:
   hero.moveXY(16, 56)
   coin = hero.findNearestItem()
   checkTakeRun(coin)
   hero.moveXY(64, 56)
   coin = hero.findNearestItem()
   checkTakeRun(coin)
type or paste code here

https://codecombat.com/play/level/short-sighted-burl?

Вы бы добавили здесь takeItem (item) Вот:

добавьте это выше hero.moveXY(40,12)
You would add takeItem(item) here:

Add it above hero.moveXY(40,12)
Lydia

Не работает. Я что то не так делаю. Третий день не могу решить, уже голова не соображает.

# Собери монеты и сбеги, пока бурл не нашёл тебя.

# This function allows your hero take an item.
def takeItem(item):
    hero.moveXY(item.pos.x, item.pos.y)

# Напиши функцию `checkTakeRun` с одним параметром.
# If the item exists, use "takeItem" function to take it.
# Двигайся на исходную точку (зелёная отметка), вне зависимости от наличия предмета.
def checkTakeRun(item):
    hero.moveXY(40, 12)
    item = hero.findNearestItem()
    if item:
        takeItem(item)
        hero.moveXY(40, 12)
    else:
        hero.moveXY(40, 12)

# Не меняй этот код.
while True:
    hero.moveXY(16, 56)
    coin = hero.findNearestItem()
    checkTakeRun(coin)
    hero.moveXY(64, 56)
    coin = hero.findNearestItem()
    checkTakeRun(coin)type or paste code here

Удалить это

Delete this:

Lydia

далите оператор else, а также первый оператор перемещения. Второй оператор перемещения должен находиться за пределами цикла if.

Delete the else statement, and also remove the first move statement. The second move statement should be outside of the if loop.

Нет? Все, что им нужно сделать, это удалить первый hero.moveXY (40,12) в функции checkTakeRun(item)
Извините, если я не понял.

No? All they have to do is delete the first hero.moveXY(40,12) in the function checkTakeRun(item)
Sorry if I was unclear.
Lydia

Спасибо большое! Меня интересует почему я не понял с первого раза? В сети нашел комментарий что эта задача ошибочно поставлена в таком порядке, ее нужно ставить позже. Так ли это? Еще меня интересует вот эта строка def takeItem(item): hero.moveXY(item.pos.x, item.pos.y)Preformatted text Почему тут нет цифр? Почему нет конкретики? Меня это вводит в заблуждение.

1 Like

Рад, что вы прошли уровень!
Чтобы ответить на ваш вопрос, в нем нет цифр, потому что он достаточно конкретен, чтобы указать вашему герою, куда идти. Но поскольку элемент может быть где угодно, положение элемента должно измениться. Было бы очень сложно предсказать, где будет находиться позиция. Так что проще сначала идентифицировать элемент и просто использовать moveXY для перехода к позиции элемента.

Glad you solve the level!
To answer your question, it has no numbers because it is specific enough to tell your hero where to go. But because an item can be anywhere, the item’s position has to change. It would be very difficult to predict where the item’s positions are going to be. So it is easier just to identify item first and just use moveXY to move to the item’s pos.
Lydia

Спасибо за ответ. Вы меня уже не в первый раз выручаете.

1 Like

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