Code Challenge: Hero Revival

Like writing code? How about a challenge featuring an earlier draft of the Hero Revival code?

Posted by on

Remember earlier, when I said "I had to rewrite my revival code again while in the middle of writing this very article." That was completely true. I was thinking it might be cool to offer a coding challenge to programmers or enthusiasts. Coding is very-much problem-solving; it is figuring out a puzzle. If you enjoy this sort of thing, then you might enjoy deducing the errors in the following code.

The code takes place over two triggers. Below, is an image of each trigger. The first trigger has no errors (of which I am aware), but you may need the information to understand the second trigger, which indeed does have errors.

First Trigger:

Second Trigger:

For your convenience, I'll also post this second trigger as text:

actionscript code:
Respawn Red With Errors
Events
Game - RealPlayerTurn becomes Equal to 1.00
Conditions
Actions
Set RedRevBaseInt = 1
Set RedRevReset = 0
Set RedHeroesRevivedInt = 0
For each (Integer A) from 1 to RedRevIntLoop, do (Actions)
Loop - Actions
Set RedRevivalCooldown[RedRevBaseInt] = (RedRevivalCooldown[RedRevBaseInt] + 1)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RedRevivalCooldown[RedRevBaseInt] Equal to 3
Then - Actions
Hero - Instantly revive RedHeroesDead[RedRevBaseInt] at (Position of Frontlines 0018 <gen>), Show revival graphics
Set RedHeroesRevivedInt = (RedHeroesRevivedInt + 1)
For each (Integer B) from 1 to (RedHeroesDeadCount - RedHeroesRevivedInt), do (Actions)
Loop - Actions
Set RedRevReset = (RedRevReset + 1)
Set RedRevivalCooldown[RedRevReset] = RedRevivalCooldown[(RedRevReset + 1)]
Set RedRevBaseInt = 1
Set RedRevReset = 0
Else - Actions
Set RedRevBaseInt = (RedRevBaseInt + 1)

The goal of the trigger is to revive any red heroes who are dead on the third turn following their deaths. The code needs to account for all possibilities. Heroes may die in any amount on any given turn, multiple heroes per turn, multiple heroes across several turns, anything. Only five heroes are available, so only five heroes may be dead at any given time.

1. Discover any and all errors in the second trigger.
2. Deduce why the errors are errors at all.
3. Give me a situation when the errors would cause the trigger to break and not do its job (revive heroes properly).
4. Optional: Rewrite the trigger so that it performs properly.

You are welcome to use your own copy of the World Editor to experiment with this code and solve the issue. However, I can say for a fact that this puzzle is solvable with mental prowess alone. Depending upon your experience with coding, you may want to review the previous posts on hero revival and on the basics of coding (Post 1. Post 2).

Naturally, this puzzle is just for fun if you're interested. But I'll throw in an extra incentive. Assuming you're actually interested in Manifest, the first person to correctly solve this challenge will gain exclusive access to my on-going closed alpha testing of Manifest. Don't want it? That's fine too; is victory not sweet enough alone?

Have questions? Post them in the comments, and I'll do what I can to help.