Funny Bug/Cheat on Max Mixer: Redeption


#1

Don’t know if this counts as a bug or not, but when I started to fool around with the code to speed up processing the list, I discovered that the following code wins the level outright:

self.say(friends)

Not sure if there is any easy way to fix this.

As an aside, I attempted to speed things up by removing the weakest friend from the list after my hero has called their name. Any suggestions as to why this code isn’t working?

friends = self.findFriends()

    loop:
        weakestFriend = None
        leastHealth = 9999
        friendIndex = 0
        
    # Tell the weakest friends to go home first.
    while friendIndex < len(friends):
        friend = friends[friendIndex]
        if friend.health < leastHealth:
            leastHealth = friend.health
            weakestFriend = friend
        friendIndex += 1
        
    if weakestFriend:
        self.say('Hey ' + weakestFriend.id + ', go home!')
        friends.remove(weakestFriend)
        weakestFriend = None

After the first pass, it keeps throwing an error that there is no value to “friend.health”… but that only makes sense if the friends list gets emptied after being read. Why would that happen?

Also, it looks like the “.remove” method isn’t enabled (perhaps due to API protections). I tried the following code:

    friends.remove(weakestFriend)
    self.say(friends)

After friends.remove(weakestFriend), weakestFriend was still appearing in the list.


#2

Looks like I’ve fixed this hilarious self.say(friends) sploit; good catch. They’ll now get confused if you say more than one name at a time.

API protection is going to prevent you from removing entries from arrays like that. I’m rather not looking forward to getting my hands dirty with further bugs in sort of thing, but I suppose it will soon become necessary!

Is the indentation correct on the code you posted?


#3

API protection, that [wc]ould explain why I can’t get “.extend” to work

Ok, got it to work, by not fiddling with API’d ‘arrays’, thanks!


#4

That’s what I kinda figured based on previous threads. Providing advanced editing functions will definitely be a headache from security terms.

In the actual code, yes.
Above, no. This happens when I’ve copied and pasted code into discourse. I just was reminded to use the backticks.


#5

I think that if you use a list comprehension to create the list, you might be able to use the remove command… Maybe I’m wrong:

friends = [f for f in self.findFriends()]


#6

Yes, that does work. Thanks!!

Tested in Desert combat

friends = [f for f in self.findFriends()]
#self.say(friends)   #displayed: Richard, Remy, Augustus, Annie, Shannon

friends.remove(self.findNearest(self.findFriends()))
#self.say(friends)   #displayed: Remy, Augustus, Annie, Shannon

(Richard, the closest, just happened to be first.)