'loop' breaks multiplayer code

Hi everyone,
I’ve recently found that a lot of my Multiplayer Treasure Grove matches end in ties. At first I thought it was my code, but closer inspection revealed that in every case it was just their hero with an error, and my hero not doing anything:

Another strange thing is that I only get the ties when fighting against red players, and the enemy hero always seems to be Tharin or Anya.

Here is my code in case there is a bug in it, in which case apologies for the disturbance:


def findBestItem(items):
    bestItem = None
    bestValue = 0
    itemsIndex = 0
    while itemsIndex < len(items):
        item = items[itemsIndex]
        if item.value / hero.distanceTo(item) > bestValue:
            bestItem = item
            bestValue = item.value / hero.distanceTo(item)
        itemsIndex += 1
    return bestItem
def summonArmy(target):
    if hero.canCast("summon-burl", target):
        hero.cast("summon-burl")
    if hero.canCast("summon-undead", target):
        hero.cast("summon-undead")
def findBestCorpse(corpses):
    bestCorpse = None
    bestValue = 0
    corpsesIndex = 0
  
    while corpsesIndex < len(corpses):
        corpse = corpses[corpsesIndex]
        corpseValue = corpse.maxHealth / hero.distanceTo(corpse)
        if corpseValue > bestValue:
            bestCorpse = corpse
            bestValue = corpseValue
        corpsesIndex += 1
    return bestCorpse
def findLunch():
    enemies = hero.findEnemies()
    enemyIndex = 0
    lunch = None
    closestLunch = 9999
    while enemyIndex < len(enemies):
        potentialLunch = enemies[enemyIndex]
        if potentialLunch:
            distance = hero.distanceTo(potentialLunch)
        if potentialLunch.health <= 200 and distance < closestLunch:
            lunch = potentialLunch
            closestLunch = distance
        enemyIndex += 1
    return lunch


def findEnemyHero():
    enemies = hero.findEnemies()
    enemyIndex = 0
    enemyHero = None 
    maxHealth = 0
    while enemyIndex < len(enemies):
        enemy = enemies[enemyIndex]
        if enemy.type == "Sorceror":
            enemyHero = enemy
        elif enemy.maxHealth > maxHealth:
            enemyHero = enemy
            maxHealth = enemy.maxHealth
        enemyIndex += 1
    return enemyHero

def spellBook(spell, target, distance):
    if target:
        e_distance = hero.distanceTo(target)
        if e_distance <= distance:
            if hero.canCast(spell, target):
                hero.cast(spell, target)
def castSpells(target):
    spellBook("fear", target, 25)
    spellBook("poison-cloud", target, 30)
def raiseDead(c):
    if c and hero.canCast("raise-dead"):
        hero.moveXY(c.pos.x, c.pos.y)
        pass
        if c:
            hero.cast("raise-dead") 
def eatLunch(lunch):
    if lunch and hero.isReady("devour"):
        hero.move(lunch.pos)
        hero.devour(lunch)
    elif lunch:
        hero.cast("drain-life", lunch)

#hero.moveXY(hero.pos.x + 5, hero.pos.y)
while True:
    lunch = findLunch()
    enemies = hero.findEnemies()
    friends = hero.findFriends()
    enemyHero = findEnemyHero()
    summonArmy(enemyHero)
    enemy = hero.findNearestEnemy()
    items = hero.findItems()
    item = findBestItem(items)
    corpses = hero.findCorpses()
    c = findBestCorpse(corpses)
    castSpells(enemyHero)
    raiseDead(c)
    eatLunch(lunch)
    if item:
        itemB = None
        items = hero.findItems()
        itemB = findBestItem(items)
        if itemB:
            hero.move(itemB.pos)
    enemy = hero.findNearestEnemy()

Note: I had to remove the Blue fox change shape function, as that word was not allowed by the codecombat word filter thing.
Thanks in advance,
Brenin Llwyd.

1 Like
# you have
def summonArmy(target):
    if hero.canCast("summon-burl", target):
        hero.cast("summon-burl")
    if hero.canCast("summon-undead", target):
        hero.cast("summon-undead")
# and you are calling the function with
summonArmy(enemyHero)

But what happens if the enemy Hero is invisible or their hero is not “operational”?
==> if hero.canCast(“summon-burl”, target) will fail I think
so a simple

if target:
    # your code here
# or
     if hero.canCast("summon-burl"):
     # or if hero.isReady("summon-burl"): will give same result as above 

side note: I gave up fighting in Multiplayer levels, because I’m using only the free heroes despite being a subscriber. It seems to me that the advantage given to the richer users as payed heroes is too big and this is depressing for children of poorer parents.

I used my non sub account (ArcaneBlade) and am number 9 in cavern survival, so even if you dont have payed heroes you still can win

Yes, I know it’s possible to be between 10th and 20th place in some multiplayer levels and I have been there for a while. But it’s true that ordinary heroes have no power even with good code to give much resistance to wizards.
About the BreninLlwyd’s problem: I didn’t test my supposition…

Hi xython,
thanks for the reply. I tried your suggestion, but unfortunately it had no effect. I’m fairly sure that my code doesn’t have any mechanical errors in it, and this seems to be backed up by the fact that the codecombat error checker doesn’t flag any issues with it either.
I think that the problem lies within the multiplayer system itself, as my brother has exactly the same problem.
On a different note, I do agree with you that the payed heroes, especially Ritic, have a big advantage in their basic stats and abilities over the free heroes. However, these barriers can be overcome with imaginative tactics and clever code, It just depends on your mindset. And finally, Codecombat would not be able to provide this incredible, free, jumping off point into the world of computer programming without subscribers like yourself, so while subscribers may seem to have an unfair advantage, they are also providing non-subscribers with a great, free resource.

Playing against Ania, Tharin, Ida, Alejandro with someone from the same ‘free’ pool results in a mutual error, and the heroes are not doing anything.
So it’s a real BUG!

Someone should post this on CoCo github.

Hello. Just to say I’ve run into this since recently restarting with CodeCombat. I see exactly the same symptoms (in Cavern Survival in case it matters), meaning my hero just stops doing anything after the first move if the enemy hero crashes. Extremely irritating! (This with a program that worked fine submitted 2 years ago and not modified etc.)

I’ve noticed the following error in the browser dev console (might be unrelated):

(My hero is in JS so I assume this is indicative of the error in the enemy hero.)

(Edit: Actually that may well be unrelated, I’ve now had the same behaviour against a JS opponent. The console in this case was clean but the problem still present.)

(Edit: The issue is on github I see: https://github.com/codecombat/codecombat/issues/5120)

2 Likes

This problem still exists. I thought it’d be somewhat enlightening to show exactly what I’m getting (and how frustrating it is.) Here’s 2 different battles, one is lost because the hero does nothing, the other is won despite the enemy hero being more powerful. (Both is fought in case this is not obvious, by the same program.)

Working as it should:

Broken example:

Should everyone who has an old code(loop ;) be not simulated? I posted duplicate codes on red and blue and am #6 on red and #1722 on blue :thinking::thinking:.

I think a script replacing loop with while (true) or while True: must be run. I’m sure there were better players in the past deserving their top places.
Edit: Every script must be tested scrupulously on a sample data before use. I don’t know why but the images in all topics before May 2015 are lost.

3 Likes

Might take a while to do, but it’ll help solve it.

@Chaboi_3000 Who can change the Simple, Easy, Hard code selections when starting out in the Multiplayer?


When playing Blue in Harrowland, the Simple CPU code locks your code up and you can’t complete the level. Even when playing red, the enemy code doesn’t work, but you don’t get locked up. Below is a post with a video showing the code being locked up when playing as Blue. I switched the opponent to the Easy enemy and it worked.

The problem is that not only loop bug in opponent’s code breaks yours. Looks like any (serious) mistake in code stops the whole party. In other words, if your hero can’t do anything on the level, your opponent’s hero stucks too. It’s annoying and unfair, but that’s the way it is(
I tried to broke my code and after 16 hrs I’m on the 3d place in ladder (with potentially #1 in a while). You can beat 1st place with one comma or point only((

Doesn’t this technically count as sharing answers since anyone with your character and similar gear could perform well even if they had no clue how to code.

No, not really, because it’s for testing out a bug. If people do take it, then that’s up to them. It’s not really a solution as such.
I do see what you mean, but it’s fine in my opinion. Besides Brenin isn’t here any more. (Really)

As for me, I saw this bug, get frustrated and think it over. I spectated this issue for a long time and struggled with it) - my blue code in cavern survival includes A LOT of lines coded specifically for this bug to avoid it. Now I used it as POC like idea of taking quite high rank doing almost nothing. Well, it worked fine - 1st place mostly after 4 or 5 days (3d for now). But I have Ideas about other more interesting and creative (and effective, I think) tactics, so I gonna quit “one-point code” for my red team on cavern survival.
I don’t take it as answer sharing, cause:

  • it does’t lay deep, smart players can pick it up by themselves pretty fast
  • it does’t work for majority of multiplayer levels becouse of many reasons
  • as @Deadpool198 mentioned, it’s not a solution) I think, it’s closer to code bug + game mechanics exploit usage.