В месте где лежит персонаж, у меня он срезает угол. Хотя должен был его обойти.
В чём может быть проблема?
I do no speak Russian but I will try to help if I can.
( нет я не говорю на русском, но я буду стараться помочь, если я могу. )
This is Python. In Python “tabs” matter
( Это Python. В Python “закладках” материя )
if a < 1 [tab]b = 2
is different from
( отличается от )
`if a < 1
b = 2’
Recheck your [tab] 's
перепроверьте [tab] 's
If you are programming in Python this might help in the future. Use comments:
( Если вы программируете в Python это может помочь в будущем. Используйте комментарии: )
while coinIndex < len(coins):
coin = coins[coinIndex]
#while
I can help a little. Google translated it wrong.
В питоне отступы очень важны и влияют на порядок выполнени команд.
the problem occurs only in one place, where there is a character in the
screenshot
Sorry for my Google translate
написал:
Пожалуйста, выложите код, так мы сможем помочь быстрее, чем пытаться вычитать код на скриншоте. Не забывайте только про форматирование кода (тройные `)
e1se: Right. Your if is part of the while loop.
Delete 1 tab from the last if.
# If there's a nearest
if nearest:
vs.
# If there's a nearest
if nearest:
# This field is covered in firetraps. Thankfully we've sent a scout ahead to find a path. He left coins along the path so that if we always stick to the nearest coin, we'll avoid the traps.
# This canyon seems to interfere with your findNearest glasses!
# You'll need to find the nearest coins on your own.
loop:
coins = hero.findItems()
coinIndex = 0
nearest = None
nearestDistance = 9999
# Loop through all the coins to find the nearest one.
while coinIndex < len(coins):
coin = coins[coinIndex]
coinIndex += 1
nearest = coins[coinIndex]
distance = self.distanceTo(coin)
# If this coin's distance is less than the nearestDistance
if distance < nearestDistance:
# Set nearest to coin
nearest = coin
# Set nearestDistance to distance
nearestDistance = distance
# If there's a nearest coin, move to its position. You'll need moveXY so you don't cut corners and hit a trap.
if nearest:
self.moveXY(nearest.pos.x, nearest.pos.y)
After the character approach to the coin number 1, he immediately goes to the coin number 2 pass over the average coin
Sorry for google translate
The google translate is ok!
(Google Translate нормально!)
Which is correct?
( Что правильно )
while coinIndex < len(coins):
if nearest:
self.moveXY(nearest.pos.x, nearest.pos.y)
or
while coinIndex < len(coins):
if nearest:
self.moveXY(nearest.pos.x, nearest.pos.y)
Should we be checking nearest:
inside the while
loop or outside the while
loop?
( Должны ли мы проверить nearest:
внутри while
во время или вне while
в то время? )
Hopefully my google translate worked?
( Надеюсь, мой Google Translate работает? )
I think that:
while coinIndex < len(coins):
if nearest:
self.moveXY(nearest.pos.x, nearest.pos.y)
is correct, but code don’t worked
We checking nearest: inside the while loop
P.S. Without google tranlate
Challenge: Trace the while loop to verify:
( Задача: Проследить то время цикла для проверки: )
coinIndex = 0
coins = [array_of_items]
nearest = None
nearestDistance = 9999
<loop 1>
coin = coins[0]
coinIndex = 1
nearest = coins[1]
distance = ?
coin’s distance is less than the nearestDistance = ? (true / false ) ?
nearest = ?
nearestDistance = ?
.
<loop 2>
?
.
<loop 3>
?
Hint:
( намек )
hero.say(distance)
Блок if nearest:
идет на том же уровне что и if distance < nearestDistance:
. То есть по сути вы будете проверять существование nearest после на каждую монету и пытаться идти к ней. а должно быть после цикла while.
Thanks Bryukh. I was trying to explain how to debug the code.
Thanks to all
Nice to talk to smart people