{{ message }}

Instantly share code, notes, and snippets.

# nwinter/NoJuice4u.js

Created Apr 9, 2015
NoJuice4u Zero Sum Winning Human Code

### Gold Collection Strategy

I initially copied my Gold Rush code over, because it was reasonably strong, and I believed that all the logic was there for a strong collection strategy.  However, as soon as I brought that code over, I blew out the hard execution limit imposed on this game mode, primarily because the “Fear” and “Goldstorm” spells can result in many coins on the battlefield.

In the end, I had to cut out half of the code to stay under the limit, because I felt that the cost of computation could be better spent on other areas. As a result, I was left with this:

• Take an inverse-exponent of the distance and value to get a vector that points towards the coin, and a magnitude that reflects how desirable it is.

• Execute this calculation on all the coins and add up all the vectors.  This is the direction that I will move.  Due to the inverse-exponent, it causes me to “gravitate” to a coin which results in a pick-up.  I never target an individual coin.

• To help reduce the execution cost, due to the inverse-exponent, I can ignore coins beyond a certain distance, because the magnitude of their vectors is too insignificant.  I use a radius variable to determine the distance, and grow/shrink that radius depending on how many gold coins/gems I find in the radius.

Unless I am casting a spell, or spawning a unit, I am collecting coins.  I do not bother to use my sorcerer to attack.  One of my earlier strategies attempted to use my sorcerer to attack enemies in range to help whittle down the enemy forces, but the problem is that if the enemy is collecting coins, they will spawn units at the same rate you kill.  Then, there’s the fact that I will no longer be collecting coins, allowing the level’s coin-density increase greatly.  This means that the opponent’s collection rate will steadily rise, while I slowly lose forces.  Eventually, I just get overwhelmed, so I decided to not bother with my sorcerer’s attack, despite the high damage and massive range.

The parts of my “Gold Rush” strategy that I couldn’t bring over was:

• Deprioritizing coins that the enemy is moving towards and is closer to than I am.
• Prioritizing coins that the enemy is moving towards but that I am closer to.
• Prioritizing coins that the enemy is moving away from.

### Spells

#### Fear

To me, Fear is the most important spell because the target loses complete control.  Since the infantry units need to receive commands from the sorcerer, fearing the sorcerer is as good as disabling the enemy’s forces.  I always fear the enemy sorcerer, unless the yeti is out and targeting my sorcerer.

#### Goldstorm

Goldstorm generates gold starting at your location, so it’s quite an increase to your gold collection rate.  You cast, and then get going with your logic again.  However, due to the one-second cast time, I make sure that there aren’t too many enemies near me when casting, because that’s too much damage to take. I can almost always outrun them, then cast.

#### Reset Cooldown

My first priority with reset cooldown is to see if I can cast fear and if the enemy sorcerer is under the effect of fear.  This sometimes lets me chain two fears on the enemy sorcerer if I’m lucky.  I don’t bother resetting the cooldown otherwise, because it’s not worth chaining any other spell.  Forcing the opponent AI to lose control is extremely valuable.

#### Mana Blast

Mana Blast was a tricky one.  Its power is proportional to the distance from center, and there seems to be an inner radius that causes a knockback.  While it’s good to run up to a large group and blast one off, it’s even better to get in the middle of them to do it.  However, I don’t use the exact center, I use the averaged vector, to maximize the damage, and maximize the opportunity to scatter the opponent’s forces.

I also have a custom logic for the “First-time mana blast” designed to scatter the opponent when our forces first engage.  As a result most battles go like this:

1. Forces engage into a fight.
2. Sorcerers go in and fear each other.
3. I mana blast the enemy forces to scatter them, which usually gives me a significant advantage.

The main goal is to spread out the enemy, so that my unit strategy can pick off the enemy individually.

Pretty much cast as soon as there are a few units within your cast radius.

#### Drain Life

Cast as a last priority.

### Unit Strategy

#### Initial Strategy

Initially, I always built 4 soldiers to start with, then move on to a 3 griffin-rider, 1 archer pattern.  I used this build pattern to refine the AI of my forces.  I started my refinements with prioritizing griffins and archers, as I felt they were the most deadly at the time.  (I didn’t know artillery existed at that time).  It worked reasonably well, until I encountered an opponent that used artillery.

Artillery was ridiculously powerful, but had a fatal flaw.  Its attacks took too long to land, and its health wasn’t very high, and it was expensive to summon.  As long as I made the artillery the “first-to-kill” target, the cannonball won’t cause much damage by the time I killed it.  I risk my forces taking additional damage to travel to the artillery, but it also means that the opponent is lacking units that can deal serious, reliable damage to my forces.

In the higher ranking levels however, the enemy’s soldiers wer actually doing considerable damage to my griffins and archers.  Due to this, I made some adjustments to move away from the soldiers.  If an opponent range is behind a soldier, I would go in to attack, and when they die, my units would scatter out to avoid taking any more damage.

Archers are usually the ones in the back, so my griffin-riders don’t spend too much time under soldier attack, and Griffin-Riders move so fast that they are almost always at the front-line.

#### Final Strategy

• If the enemy has 1.75 times more soldiers than me, I summon a soldier when I have the gold.  I need to ensure that I have some soldiers if my opponent also has some, due to their tankiness, and cheap cost.
• Otherwise, I always spawn 3 griffin-riders, then 1 archer in an alternating pattern.  The reason I don’t spawn many archers, is because their health is extremely low.  I find their merit comes from their range and speed (lack thereof), where they can avoid certain disasters if they aren’t actively being hunted.  Otherwise, the griffin-riders can take much more damage.  I often see the enemy sorcerer mana blasting my griffin-riders, and my archers happen to be outside the range, due to their speed.

Now, my battle strategy is broken up into a few phases.  First is the “Pre-initiation” phase.

• I command all units except soldiers to move to my position.  I don’t use defend, because I don’t want them to run out to attack without my explicit order.  In addition, if I get feared, they will stay put.  In “defend” mode, they might try to attack the enemy, and then overshoot the enemy when I am feared.
• I command all my soldiers to attack the nearest enemy.  Their goal is to be the front line, and hold that line so that when it’s time to initiate, my griffin riders and archers will launch their attack from behind my soldiers.
• The “Pre-initiation” phase ends when the game time exceeds 10, or an enemy comes within range of any of my units.  I chose 10 seconds, because it’s enough time for my soldiers to get close enough that I can initiate.

Next is the initiation phase:

• Soldier AI remains the same.  They’re my meat shields.
• I add up all enemies that are in range to attack any of my units excluding the sorcerer into an array, and apply a score modifier based on the unit type, health remaining and distance to determine what to focus fire.  This allows my archers and griffin-riders to focus certain targets to reduce the enemy numbers quickly.  Generally the priority resolves to: Artillery, Archers, Griffin-Riders, Soldiers if everything is at full health.
• The above strategy factors in distance in such a way that if my forces get scattered somehow, they will cluster up into multiple small groups to focus fire their area, and eventually coalesce back into a large group.
• If a soldier or sorcerer gets too close to my range, I move that unit towards an escape vector to kite and avoid taking unnecessary damage.  I don’t run away from ranged opponents, because it’s better to fight them head-on.  However the enemy sorcerer’s “Mana Blast” is extremely deadly so I make sure my range try to attack at half to max range, to reduce the damage taken from a mana blast, and it also helps prevent my ranged units from clustering, which would be easily devastated by a well-placed mana blast.
• As mentioned earlier, I have a “First time mana blast” logic that explicitly goes in and fires off a blast.  It’s slightly different from my standard strategy.  After that, I scan for opportunities to execute a mana blast based on the clustering of enemies, and whether I am close enough that the detour is worth it.

Then there’s the yeti phase:

• At the yeti phase, I issue all my forces to attack the enemy sorcerer.  The reason for this is because the yeti runs insanely fast and kills fast.  If I clutter my forces on the enemy sorcerer, it’s less likely that the yeti will kill a unit, and then move to a unit that is closer to me, and eventually reach me.
• If the yeti does decide to attack me, I fear it, and continue on my coin collection strategy.  I rely on spawning new units and moving them to the enemy to direct the yeti to the opponent.
• If the yeti is attacking a unit of mine, I explicitly issue it a move command to the enemy sorcerer’s position.  The reason I use a position, and not the enemy sorcerer is because it’s more predictable what will happen if I get feared while this is happening.  Targeting the sorcerer directly can cause the unit to “overshoot”, and put your forces out of position.
• At this point, I no longer have absolute priority on fearing the enemy sorcerer.  I only fear them if they are closer to me than the yeti is.
• However, my yeti phase logic is very unpolished, and I believe most of my losses probably happened in this phase.