#Tower Defense (Work in Progress) [tag:game] [tag:king-of-the-hill] [tag:javascript] --- [Picture will go here] Tower Defense is a format for casual games that was popularized in the Flash era. The player places towers that shoot down invaders moving along a predefined path. #The Challenge There will be two types of submissions: Defenders and Invaders. These will compete with each other. The playfield is a 1-dimensional "grid" that is 100 spaces long. Towers can be placed along this playfield, which will do damage to the invader that is farthest along within its range. Both sides will become stronger between rounds. The game ends after 100 invaders have made it through the defender's playfield. The game will be simulated deterministically in a turn based fashion. Invaders cannot pass through each other and only one can be on each space. They move forward one space each turn, if possible, resolved farthest-along-first. ##Defenders The objective of the defender is to last as many turns as possible by keeping invaders from getting across the playfield. At the beginning of the game, the defender will have 50 gold. They have the following options available to them, each costing 10 gold: * Place a turret on the playfield. Turrets initially have a range of 1 and do 1 damage (1 power) and fire once per turn. * Place a stunner on the playfield. Stunners do not deal damage, have an initial range of 0, but prevent targeted invaders from moving for a number of turns equal to their power. After firing, they have a cooldown time of `power + 1`. They will not fire at an already-stunned invader. * Place a bomb on the playfield. Bombs have an initial range of 2 and power of 1, but damage *all* invaders in range. They have a cooldown of 5 turns before being able to fire again. They are only triggered if an invader is immediately in front of them. * Increase a tower's power by 1. Power affects damage for bombs and turrets and stun time (but also cooldown time) for stunners * Increase a tower's range by 1. Only one building can be placed on each space. When a building is placed or upgraded, it cannot fire or be upgraded for 10 turns. Buildings may also be removed to regain half the gold invested into them. 1 Gold is earned once every 10 turns. One action may be taken each turn. ###Range Building range refers to the number of spaces on either side of the building that can be reached by the turret. ... | | |A| | | | |B| | | | ... ... 5-4-3-2-1-T-1-2-3-4-5 ... A turret is represented by `T` and there are invaders `A` and `B`. If the turret had a range of 0, it would only be able to fire at the space immediately in front of it. If it had a range of 2, it would be able to reach invader `B` only. If it has a range of 3, it would be able to reach both invaders `A` and `B`. ##Invaders The objective of the invaders is to get 100 invaders through the playfield in as few turns as possible. The invaders start out with 0 gold. Every 10 turns, some amount of gold is earned. The amount earned every 10 turns starts at 10 gold and increases by `floor(log(turnNumber) - 1)` every 100 turns. Each turn, you may spawn an invader. At minimum, it costs 10 gold and has a base HP of 10. You can spend additional gold to increase its power: * (1G) +1 HP * (10G) +1 Defense (reduce damage taken by 1, but not lower than 1) * (10G) +1 Stun resistance (reduces stun time by 1 turn) You are limited on the maximum stats. You start off unable to boost stats, but every 100 turns, the maximum increases by `floor(log(turnNumber))` You cannot spawn an invader if there is already an invader on the first space of the board. Therefore, a potential counterplay from defenders to prevent massive hordes of invaders is to put stunners on the first few spaces. To ensure that even the most basic invader AIs will eventually overwhelm defenders (assuming they actually spawn invaders), a multiplier on HP will be applied which exponentially increases by 10% every 10,000 rounds. (HP will still be rounded down to the nearest integer) # Implementation The main game / AI driver is [here][1] (still a work in progress) Submission logistics TBD Both the Defender and Invaders will have complete knowledge about the state of the game and will be allowed to maintain state from the beginning of the game. They may not directly modify the game state. Any attempts to do so will be disqualified. (api description will go here) Defenders should return an object with an `action` property that is either `'build'`, `'upgrade'`, or `'destroy'`. Each requires some additional properties to be set: (will add later) Invaders should return an object which contains any stat boosts desired: `hp`, `defense`, and `stunRes`. Both defenders or invaders may also return undefined or null to indicate not taking an action. AIs must return their desired action in less than 15 milliseconds, averaged over 100 turns. Invalid actions returned by the AI will be ignored. # Rules * No abusing standard loopholes * No direct modification of the game state passed to you. It will *not* be defensively deep-copied. * Obfuscated submissions will be assumed to be cheating. * Any uncaught exceptions will result in disqualification. * Implementations must be totally deterministic, i.e. random number generators are only allowed if seeded consistently (either with a constant or with game state) and must use isolated random state which the other AI in play cannot access. # Scoring Each Defender will face off against each Invader (not including any submissions by him). The number of turns the defender lasted will be averaged across all opponents and that will be its score. The Defender with the highest score and the Invader with the lowest score will be the winners. [1]: http://Beefster09.github.io/pcg-tower-defense/tower-defense.html