[Adventurer] Wireless

It’s the last node in the linked list of levels about linked lists Wireless

I tried to make that level simple enough. Maybe it’s too simple for Glacier. I’ll be grateful for any feedback.

2 Likes

Typo her in if robot is dead you wrote if robot iss dead.
12

@Bryukh can you help here:

# This function finds a broken list elements.
def diagnoseList(linkedList):
    current = linkedList
    # Use "next" property to iterate the list.
    # If some robot iss dead, return that robot:
    while current:
        if current.health<0:
            return current
        return None
    # If all are "healthy".
    

Look at previous levels and how iterate a linked list.

I’m doing ok, but the final robot never links up. It works fine for replacing the first 2 broken bots, but not the third one. I think the third one ends up being damaged because of a plasma ball right after the first replacement. One ball always gets sent toward the location of the replacement, but the replacement has moved, so it hits an unused replacement.

It’s the last node.

Hm, I can’t get that effect. Could you give sessionID with that problem?

Here’s a screenshot, note how things have worked well, with 2 bots stepping in to replace a broken one, but the third replacement never does anything:

|Kos’s Woodhouse| Generated random seed 6674763034 of type submissionCount from sessionIDs 59a7decd45e0b0002058237b submissionCount 2

It’s weird. The plasma ball distance is not enough to hit backup robots. Also as I can see for that session – the last robot isn’t damaged but ignored.

Ha Ha! I found the mistake in your code

while current:
   if current.health < 0:

Health can be 0 :wink:

3 Likes
if current.health <= 0:

The level doesn’t finish for me either.


Check the video description for the list of bugs.

(Actually, I pressed submit again to get another random seed. This time, the middle robot was the one to be replaced. The peasants were finally saved. However, the last replacement robot didn’t move, just as @dwhittaker has explained.)

@Bryukh
The level isn’t finishing for me either, but in my case, the backup robot replaces the broken robot in time, but when the previous robot shoots a plasma ball at it, it just takes the damage and doesn’t pass it on.

here is my code:

# Destroy the door and ogres.

# Backup robots are stronger.
def findBackupRobots():
    robots = hero.findByType("robot-walker")
    reserveRobots = []
    for robot in robots:
        if robot.health > 5000:
            reserveRobots.push(robot)
    return reserveRobots

# The function replaces a node in the list.
def replaceMissingLink(linkedList, broken, replacement):
    current = linkedList
    prev = None
    while current:
        if current == broken:
            if prev:
                # Use "setNext" to assign the next node.
                prev.setNext(replacement)
            # Set the next node for the replacement robot:
            current.setNext(replacement)
            break
        prev = current
        current = current.next

# This function finds a broken list elements.
def diagnoseList(linkedList):
    current = linkedList
    # Use "next" property to iterate the list.
    # If some robot iss dead, return that robot:
    while current:
        if current.health <= 0:
            return current
        else:
            current = current.next
        # If all are "healthy".
    return None

# The head of the linked list of robots.
robotList = hero.findNearest(hero.findFriends())
while True:
    backUpRobots = findBackupRobots()
    brokenRobot = diagnoseList(robotList)
    if brokenRobot and len(backUpRobots):
        replaceMissingLink(robotList, brokenRobot, backUpRobots[0])

Is there some way to encase the code in a box so the post is less lengthy and messy?

Thanks. I see a problem.

Because you don’t set next for the replacement. Look careful at your code and read that comment

# Set the next node for the replacement robot:

OHHH!!

Got it Bryukh, thanks :smiley:

But I found another bug in the level
When i ran the code using the previous seed, it says success, but when i submit, one of the robot’s plasma balls hit a peasant

can you attempt to fix the bug?

I have the same problem as @dwhittaker with this code:

[taking out working code]

Probably need to fix this.
Edit:
This is an “unlucky submit” problem I tried another times it didn’t hit the backup and it worked. :smile: :smile:

Thanks. Fixed. [20 chars]

Important you can’t assign the next property directly, use the method setNext(unit) for that.

But replacement.next =current.next works for me …

1 Like

JS or python? [20 chars]