[Adventurer] First Out

Let’s start the new level series. Now about queues: First Out

Enqueue soldiers and peasants in the right order. Next send them out (dequeue) to defeat ogres and take their treasures.

2 Likes

Great and fun level @Bryukh. Is there going to be more of those levels?

Good concept, but the soldiers aren’t always successful. I succeeded in my practice, then had to submit 4 times before actually succeeding. Balance is a little off.

Well done in blocking spells. I tried to swap with the sergeant. “Brrrr!”

No bonus for collecting all 4 gems?

Yes.

Hm, I’ve tried it several times without problems, there are no random elements. Danny, could you send me your code to be sure (it’s easy to balance but first I want to find a problem)?

It’s too easy :slight_smile:

Yeah, we’ve fixed “first frame race” problem.

Here’s a bug i found in First Out.
After i enqueue all the soldiers, I enqueued all the peasants.
Then, when i dequeue both peasants, the first peasant grabs a gem and goes back to camp, while the other goes to where the gem was and return empty handed.
I think both peasants were coded to go for the same gem

here’s my code in python:

# Defeat incoming ogres and bring gems.
units = hero.findFriends()
# The sergeant can command by units.
sergeant = hero.findByType("paladin", units)[0]
# The scout will help to find enemies.
scout = hero.findByType("griffin-rider", units)[0]
soldiers = hero.findByType("soldier", units)
peasants = hero.findByType("peasant", units)

# First we need prepare soldiers. First we need prepare soldiers.
for soldier in soldiers:
    # The sergeant can command to enqueue an unit.
    sergeant.enqueue(soldier)
# Now prepare and "enqueu" peasants.
for peasant in peasants:
    sergeant.enqueue(peasant)

while True:
    enemy = scout.findNearestEnemy()
    # When enemies are here.
    if enemy:
        for s in soldiers:
            # Send soldiers with the "dequeue" method.
            sergeant.dequeue()
        break

while True:
    enemy = scout.findNearestEnemy()
    # If enemies are dead.
    if not enemy:
        # "dequeue" the remaining peasants
        sergeant.dequeue(peasants[1])
        sergeant.dequeue(peasants[0])

I can’t reproduce it. Could you say your nickname in CodeCombat? I’ll try to look at the problem with your account.

1 Like

SuperSmacker is my username
thanks for your help :smiley:

I hope I’ve fixed it. Thank you for the report!

Yes it is now working perfectly, thank you for your edits :smiley: